diff --git a/Yavsc.Server/Models/Identity/ApplicationUser.cs b/Yavsc.Server/Helpers/ApplicationUser.cs similarity index 100% rename from Yavsc.Server/Models/Identity/ApplicationUser.cs rename to Yavsc.Server/Helpers/ApplicationUser.cs diff --git a/Yavsc.Server/Models/Billing/NominativeServiceCommand.cs b/Yavsc.Server/Models/Billing/NominativeServiceCommand.cs index fe041ab9..0ccf7991 100644 --- a/Yavsc.Server/Models/Billing/NominativeServiceCommand.cs +++ b/Yavsc.Server/Models/Billing/NominativeServiceCommand.cs @@ -65,7 +65,7 @@ namespace Yavsc.Models.Billing public DateTime? ValidationDate {get; set;} - [Display(Name="Montant prévisionel de la préstation")] + [Display(Name="Previsional")] public decimal? Previsional { get; set; } /// /// The bill diff --git a/Yavsc.Server/ViewModels/Account/LoginViewModel.cs b/Yavsc.Server/ViewModels/Account/LoginViewModel.cs index 12bb36f7..ef0c56d0 100755 --- a/Yavsc.Server/ViewModels/Account/LoginViewModel.cs +++ b/Yavsc.Server/ViewModels/Account/LoginViewModel.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using Microsoft.AspNet.Http.Authentication; namespace Yavsc.ViewModels.Account { @@ -49,6 +48,13 @@ namespace Yavsc.ViewModels.Account /// Lists external identity provider descriptions. /// /// an enumeration of the descriptions. - public IEnumerable ExternalProviders { get; set; } + public IEnumerable ExternalProviders { get; set; } + } + + public class YaAuthenticationDescription { + public string DisplayName { get; set; } + public string AuthenticationScheme { get; set; } + + public IDictionary Items { get; set; } } } diff --git a/Yavsc.Server/ViewModels/Account/Me.cs b/Yavsc.Server/ViewModels/Account/Me.cs index 1cd7d954..83264bdf 100644 --- a/Yavsc.Server/ViewModels/Account/Me.cs +++ b/Yavsc.Server/ViewModels/Account/Me.cs @@ -1,14 +1,14 @@ namespace Yavsc.Models.Auth { public class Me : IApplicationUser { - public Me(ApplicationUser user) + public Me(string userId, string userName, string email, string avatar, ILocation address, string gCalId) { - Id = user.Id; - UserName = user.UserName; - EMail = user.Email; - Avatar = user.Avatar; - PostalAddress = user.PostalAddress; - DedicatedGoogleCalendar = user.DedicatedGoogleCalendar; + Id = userId; + UserName = userName; + EMail = email; + Avatar = avatar; + PostalAddress = address; + DedicatedGoogleCalendar = gCalId; } public string Id { get; set; } public string UserName { get; set; } diff --git a/Yavsc.Server/ViewModels/Administration/RoleInfo.cs b/Yavsc.Server/ViewModels/Administration/RoleInfo.cs index 86bddde1..2a1574ee 100644 --- a/Yavsc.Server/ViewModels/Administration/RoleInfo.cs +++ b/Yavsc.Server/ViewModels/Administration/RoleInfo.cs @@ -1,5 +1,4 @@ using System.Linq; -using Microsoft.AspNet.Identity.EntityFramework; namespace Yavsc.ViewModels.Administration { @@ -9,11 +8,11 @@ namespace Yavsc.ViewModels.Administration { } - public RoleInfo ( IdentityRole role) + public RoleInfo ( string roleName, string roleId, string[] users) { - Name = role.Name; - Id = role.Id; - Users = role.Users.Select(u => u.UserId).ToArray(); + Name = roleName; // role.Name; + Id = roleId; // role.Id; + Users = users ; // role.Users.Select(u => u.UserId).ToArray(); } public string Id { get; set; } public string Name { get; set; } diff --git a/Yavsc/ApiControllers/AccountController.cs b/Yavsc/ApiControllers/AccountController.cs index b18806e8..b6c5cdf0 100644 --- a/Yavsc/ApiControllers/AccountController.cs +++ b/Yavsc/ApiControllers/AccountController.cs @@ -141,7 +141,9 @@ namespace Yavsc.WebApi.Controllers .Include(u=>u.Roles) .FirstAsync(u=>u.Id == uid); - var user = new Me(userData); + var user = new Me(userData.Id, userData.UserName, userData.Email, + userData.Avatar , + userData.PostalAddress, userData.DedicatedGoogleCalendar ); var userRoles = _dbContext.UserRoles.Where(u=>u.UserId == uid).ToArray(); diff --git a/Yavsc/Controllers/Accounting/AccountController.cs b/Yavsc/Controllers/Accounting/AccountController.cs index 06faecf1..373960aa 100644 --- a/Yavsc/Controllers/Accounting/AccountController.cs +++ b/Yavsc/Controllers/Accounting/AccountController.cs @@ -20,6 +20,7 @@ using Newtonsoft.Json; namespace Yavsc.Controllers { + using Microsoft.AspNet.Http.Authentication; using Yavsc.Abstract.Manage; using Yavsc.Helpers; @@ -84,6 +85,7 @@ namespace Yavsc.Controllers var properties = _signInManager.ConfigureExternalAuthenticationProperties(OpenIdConnectDefaults.AuthenticationScheme, returnUrl); return new ChallengeResult(OpenIdConnectDefaults.AuthenticationScheme, properties); */ + } [AllowAnonymous] diff --git a/Yavsc/Helpers/AuthHelpers.cs b/Yavsc/Helpers/AuthHelpers.cs index 790e4c6a..229793c5 100644 --- a/Yavsc/Helpers/AuthHelpers.cs +++ b/Yavsc/Helpers/AuthHelpers.cs @@ -3,17 +3,24 @@ using System.Linq; using System.Collections.Generic; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Authentication; +using Yavsc.ViewModels.Account; namespace Yavsc.Helpers { public static class HttpContextExtensions { - public static IEnumerable GetExternalProviders(this HttpContext context) { + public static IEnumerable GetExternalProviders(this HttpContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } return from description in context.Authentication.GetAuthenticationSchemes() where !string.IsNullOrEmpty(description.DisplayName) - select description; + select + ( new YaAuthenticationDescription + { + DisplayName = description.DisplayName, + AuthenticationScheme = description.AuthenticationScheme, + Items = description.Items + });; } public static bool IsProviderSupported(this HttpContext context, string provider) { diff --git a/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx b/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx index 3b2190b6..4f0d5f5c 100644 --- a/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx +++ b/Yavsc/Resources/Yavsc.Resources.YavscLocalisation.fr.resx @@ -336,6 +336,7 @@ Date souhaitée Lieu de la présation: {0}.\n PrévisualiserPrévisualiser le document + Montant prévisionel de la préstation Édition du profil Référence produit prestation diff --git a/Yavsc.Server/Services/MessageServices.cs b/Yavsc/Services/GCMSender.cs old mode 100755 new mode 100644 similarity index 54% rename from Yavsc.Server/Services/MessageServices.cs rename to Yavsc/Services/GCMSender.cs index 133d017b..90bc8d57 --- a/Yavsc.Server/Services/MessageServices.cs +++ b/Yavsc/Services/GCMSender.cs @@ -1,48 +1,36 @@ - -using System.Threading.Tasks; -using MailKit.Net.Smtp; -using MimeKit; -using MailKit.Security; using System; -using Yavsc.Models.Messaging; -using Microsoft.AspNet.Identity; -using Yavsc.Models; -using Yavsc.Models.Google.Messaging; using System.Collections.Generic; -using Yavsc.Models.Haircut; -using Yavsc.Interfaces.Workflow; using System.Linq; +using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.OptionsModel; using Newtonsoft.Json; +using Yavsc.Interfaces.Workflow; +using Yavsc.Models.Google.Messaging; +using Yavsc.Models.Haircut; +using Yavsc.Models.Messaging; using Yavsc.Server.Helpers; -using Microsoft.Extensions.OptionsModel; -using Yavsc.Abstract.Manage; namespace Yavsc.Services { - // This class is used by the application to send Email and SMS - // when you turn on two-factor authentication in ASP.NET Identity. - // For more details see this link http://go.microsoft.com/fwlink/?LinkID=532713 - public class MessageSender : IEmailSender, IGoogleCloudMessageSender + public class GCMSender : IGoogleCloudMessageSender { private ILogger _logger; SiteSettings siteSettings; - SmtpSettings smtpSettings; GoogleAuthSettings googleSettings; - public MessageSender( + public GCMSender( + ILoggerFactory loggerFactory, IOptions sitesOptions, IOptions smtpOptions, IOptions googleOptions - ) - { - _logger = loggerFactory.CreateLogger(); + ) + { _logger = loggerFactory.CreateLogger(); siteSettings = sitesOptions?.Value; - smtpSettings = smtpOptions?.Value; googleSettings = googleOptions?.Value; - } + } public async Task NotifyEvent ( IEnumerable regids, Event ev) where Event : IEvent @@ -74,15 +62,7 @@ namespace Yavsc.Services } } - /// - /// - /// - /// - /// - /// - /// a MessageWithPayloadResponse, - /// bool somethingsent = (response.failure == 0 && response.success > 0) - /// + public async Task NotifyBookQueryAsync( IEnumerable registrationIds, RdvQueryEvent ev) { return await NotifyEvent(registrationIds, ev); @@ -99,53 +79,11 @@ namespace Yavsc.Services return await NotifyEvent(registrationIds, ev); } - public Task SendEmailAsync(string username, string email, string subject, string message) + public async Task NotifyAsync(IEnumerable regids, IEvent yaev) { - EmailSentViewModel model = new EmailSentViewModel{ EMail = email }; - try - { - MimeMessage msg = new MimeMessage(); - msg.From.Add(new MailboxAddress( - siteSettings.Owner.Name, - siteSettings.Owner.EMail)); - msg.To.Add(new MailboxAddress(username, email)); - msg.Body = new TextPart("plain") - { - Text = message - }; - msg.Subject = subject; - msg.MessageId = MimeKit.Utils.MimeUtils.GenerateMessageId( - siteSettings.Authority - ); - using (SmtpClient sc = new SmtpClient()) - { - sc.Connect( - smtpSettings.Host, - smtpSettings.Port, - SecureSocketOptions.None); - sc.Send(msg); - model.MessageId = msg.MessageId; - } - } - catch (Exception ex) - { - model.Sent = false; - model.ErrorMessage = ex.Message; - return Task.FromResult(model); - } - return Task.FromResult(model); - } - - public Task ValidateAsync(string purpose, string token, UserManager manager, ApplicationUser user) - { - throw new NotImplementedException(); - } - - public Task NotifyAsync( - IEnumerable regids, IEvent yaev) - { - throw new NotImplementedException(); + return await NotifyEvent(regids, yaev); } + /* SMS with Twilio: public Task SendSmsAsync(TwilioSettings twilioSettigns, string number, string message) { @@ -159,4 +97,4 @@ return Task.FromResult(result.Status != "Failed"); } */ } -} +} \ No newline at end of file diff --git a/Yavsc/Services/MailSender.cs b/Yavsc/Services/MailSender.cs new file mode 100644 index 00000000..e3e169c5 --- /dev/null +++ b/Yavsc/Services/MailSender.cs @@ -0,0 +1,79 @@ +using System; +using System.Threading.Tasks; +using MailKit.Net.Smtp; +using MailKit.Security; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.OptionsModel; +using MimeKit; +using Yavsc.Abstract.Manage; + +namespace Yavsc.Services +{ + public class MailSender : IEmailSender + { + private ILogger _logger; + SiteSettings siteSettings; + SmtpSettings smtpSettings; + + public MailSender( + ILoggerFactory loggerFactory, + IOptions sitesOptions, + IOptions smtpOptions, + IOptions googleOptions + ) + { + _logger = loggerFactory.CreateLogger(); + siteSettings = sitesOptions?.Value; + smtpSettings = smtpOptions?.Value; + } + + /// + /// + /// + /// + /// + /// + /// a MessageWithPayloadResponse, + /// bool somethingsent = (response.failure == 0 && response.success > 0) + /// + + + public async Task SendEmailAsync(string username, string email, string subject, string message) + { + EmailSentViewModel model = new EmailSentViewModel{ EMail = email }; + try + { + MimeMessage msg = new MimeMessage(); + msg.From.Add(new MailboxAddress( + siteSettings.Owner.Name, + siteSettings.Owner.EMail)); + msg.To.Add(new MailboxAddress(username, email)); + msg.Body = new TextPart("plain") + { + Text = message + }; + msg.Subject = subject; + msg.MessageId = MimeKit.Utils.MimeUtils.GenerateMessageId( + siteSettings.Authority + ); + using (SmtpClient sc = new SmtpClient()) + { + sc.Connect( + smtpSettings.Host, + smtpSettings.Port, + SecureSocketOptions.None); + sc.Send(msg); + model.MessageId = msg.MessageId; + } + } + catch (Exception ex) + { + model.Sent = false; + model.ErrorMessage = ex.Message; + return model; + } + return model; + } + + } +} \ No newline at end of file diff --git a/Yavsc/Services/MessageServices.cs b/Yavsc/Services/MessageServices.cs new file mode 100755 index 00000000..67b99c3b --- /dev/null +++ b/Yavsc/Services/MessageServices.cs @@ -0,0 +1,27 @@ + +using System.Threading.Tasks; +using MailKit.Net.Smtp; +using MimeKit; +using MailKit.Security; +using System; +using Yavsc.Models.Messaging; +using Yavsc.Models; +using Yavsc.Models.Google.Messaging; +using System.Collections.Generic; +using Yavsc.Models.Haircut; +using Yavsc.Interfaces.Workflow; +using System.Linq; +using Newtonsoft.Json; +using Yavsc.Server.Helpers; +using Yavsc.Abstract.Manage; +using Microsoft.AspNet.Identity; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.OptionsModel; + +namespace Yavsc.Services +{ + // This class is used by the application to send Email and SMS + // when you turn on two-factor authentication in ASP.NET Identity. + // For more details see this link http://go.microsoft.com/fwlink/?LinkID=532713 + +} diff --git a/Yavsc/Startup/Startup.OAuth.cs b/Yavsc/Startup/Startup.OAuth.cs index 55e4ae18..afe119a7 100644 --- a/Yavsc/Startup/Startup.OAuth.cs +++ b/Yavsc/Startup/Startup.OAuth.cs @@ -172,14 +172,14 @@ namespace Yavsc }; branch.UseMiddleware(YavscGoogleAppOptions); - +/* FIXME 403 branch.UseTwitterAuthentication(options=> { TwitterAppOptions = options; options.ConsumerKey = Configuration["Authentication:Twitter:ClientId"]; options.ConsumerSecret = Configuration["Authentication:Twitter:ClientSecret"]; - }); + }); */ branch.UseOAuthAuthorizationServer( diff --git a/Yavsc/Startup/Startup.cs b/Yavsc/Startup/Startup.cs index 15849975..69c311d6 100755 --- a/Yavsc/Startup/Startup.cs +++ b/Yavsc/Startup/Startup.cs @@ -242,8 +242,8 @@ namespace Yavsc services.AddTransient, TicketDataFormat>(); // Add application services. - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient( (sp) => new FileDataStore("googledatastore",false) ); services.AddTransient(); diff --git a/Yavsc.Server/ViewModels/Auth/ViewFileContext.cs b/Yavsc/ViewModels/Auth/ViewFileContext.cs similarity index 100% rename from Yavsc.Server/ViewModels/Auth/ViewFileContext.cs rename to Yavsc/ViewModels/Auth/ViewFileContext.cs diff --git a/Yavsc.Server/ViewModels/Manage/IndexViewModel.cs b/Yavsc/ViewModels/Manage/IndexViewModel.cs similarity index 100% rename from Yavsc.Server/ViewModels/Manage/IndexViewModel.cs rename to Yavsc/ViewModels/Manage/IndexViewModel.cs diff --git a/Yavsc.Server/ViewModels/Manage/ManageLoginsViewModel.cs b/Yavsc/ViewModels/Manage/ManageLoginsViewModel.cs similarity index 100% rename from Yavsc.Server/ViewModels/Manage/ManageLoginsViewModel.cs rename to Yavsc/ViewModels/Manage/ManageLoginsViewModel.cs diff --git a/Yavsc/Views/Project/Delete.cshtml b/Yavsc/Views/Project/Delete.cshtml index e3fc40b1..7f42e570 100644 --- a/Yavsc/Views/Project/Delete.cshtml +++ b/Yavsc/Views/Project/Delete.cshtml @@ -36,10 +36,10 @@ @Html.DisplayFor(model => model.Description)
- @Html.DisplayNameFor(model => model.LocalRepo) + @Html.DisplayNameFor(model => model.Repository)
- @Html.DisplayFor(model => model.LocalRepo) + @Html.DisplayFor(model => model.Repository)
@Html.DisplayNameFor(model => model.OwnerId) diff --git a/Yavsc/Views/Project/Details.cshtml b/Yavsc/Views/Project/Details.cshtml index af07a929..c8d022d1 100644 --- a/Yavsc/Views/Project/Details.cshtml +++ b/Yavsc/Views/Project/Details.cshtml @@ -10,6 +10,12 @@

Project


+
+ @Html.DisplayNameFor(model => model.Name) +
+
+ @Html.DisplayFor(model => model.Name) +
@Html.DisplayNameFor(model => model.Consent)
@@ -35,10 +41,10 @@ @Html.DisplayFor(model => model.Description)
- @Html.DisplayNameFor(model => model.LocalRepo) + @Html.DisplayNameFor(model => model.Repository)
- @Html.DisplayFor(model => model.LocalRepo) + @Html.DisplayFor(model => model.Repository)
@Html.DisplayNameFor(model => model.OwnerId) diff --git a/Yavsc/Views/Project/Edit.cshtml b/Yavsc/Views/Project/Edit.cshtml index 91a1bccd..096adc49 100644 --- a/Yavsc/Views/Project/Edit.cshtml +++ b/Yavsc/Views/Project/Edit.cshtml @@ -13,88 +13,31 @@
- +
- +
- -
- - -
-
- -
- -
- - -
-
-
- -
- - -
-
-
- +
- -
-
-
- -
- - -
-
-
- -
- - + +
- -
- - -
-
-
- +
- +
@@ -105,13 +48,6 @@
-
- -
- - -
-
@@ -119,27 +55,6 @@
-
- -
- - -
-
-
- -
- - -
-
-
- -
- - -
-
diff --git a/Yavsc/Views/Project/Index.cshtml b/Yavsc/Views/Project/Index.cshtml index 519a440b..e206d884 100644 --- a/Yavsc/Views/Project/Index.cshtml +++ b/Yavsc/Views/Project/Index.cshtml @@ -11,6 +11,9 @@

+ @@ -55,6 +58,9 @@ @foreach (var item in Model) { + diff --git a/cli/Program.cs b/cli/Program.cs index acb7b52d..872e1304 100644 --- a/cli/Program.cs +++ b/cli/Program.cs @@ -1,25 +1,8 @@ -using System; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.OptionsModel; - -using System.Globalization; -using System.Reflection; // using Microsoft.AspNet.Authorization; -using Microsoft.AspNet.Builder; // using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Identity.EntityFramework; -using Microsoft.AspNet.Localization; -using Microsoft.AspNet.Mvc; -using Microsoft.AspNet.Mvc.Filters; -using Microsoft.AspNet.Mvc.Razor; -using Microsoft.Net.Http.Headers; -using Microsoft.AspNet.Razor; -using Microsoft.Extensions.DependencyInjection.Abstractions; -using Microsoft.Extensions.PlatformAbstractions; using cli.Services; namespace cli diff --git a/cli/Services/EMailer.cs b/cli/Services/EMailer.cs index ce2afa32..0393d197 100644 --- a/cli/Services/EMailer.cs +++ b/cli/Services/EMailer.cs @@ -1,29 +1,23 @@ using System; using System.IO; -using System.CodeDom; -using System.CodeDom.Compiler; using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Text; +using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Emit; using Microsoft.AspNet.Razor; -using Microsoft.AspNet.Razor.Generator; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; -using Microsoft.CSharp; using Microsoft.AspNet.Identity.EntityFramework; -using Newtonsoft.Json; using Yavsc.Models; -using Yavsc.Models.Identity; using Yavsc.Templates; using Yavsc.Abstract.Templates; using Yavsc.Services; - +using Yavsc.Abstract.Manage; namespace cli.Services { @@ -172,13 +166,17 @@ namespace cli.Services generatedtemplate.User = user; generatedtemplate.ExecuteAsync(); logger.LogInformation(generatedtemplate.GeneratedText); - var mailSentInfo = this.mailSender.SendEmailAsync - (user.UserName, user.Email, $"monthly email", generatedtemplate.GeneratedText).Result; - if (!mailSentInfo.Sent) + EmailSentViewModel mailSentInfo = this.mailSender.SendEmailAsync + (user.UserName, user.Email, $"monthly email", generatedtemplate.GeneratedText).Result; + if (mailSentInfo==null) + logger.LogError("No info on sending"); + else if (!mailSentInfo.Sent) logger.LogError($"{mailSentInfo.ErrorMessage}"); else logger.LogInformation($"mailId:{mailSentInfo.MessageId} \nto:{user.UserName}"); + + } } diff --git a/cli/Startup.cs b/cli/Startup.cs index ebe09199..676a50ae 100644 --- a/cli/Startup.cs +++ b/cli/Startup.cs @@ -57,7 +57,7 @@ namespace cli var smtpSettingsconf = Configuration.GetSection("Smtp"); services.Configure(smtpSettingsconf); services.AddInstance(typeof(ILoggerFactory), new LoggerFactory()); - services.AddTransient(typeof(IEmailSender), typeof(MessageSender)); + services.AddTransient(typeof(IEmailSender), typeof(MailSender)); services.AddTransient(typeof(RazorEngineHost), typeof(YaRazorEngineHost)); services.AddEntityFramework().AddNpgsql().AddDbContext(); services.AddTransient((s) => new RazorTemplateEngine(s.GetService())); diff --git a/cli/project.json b/cli/project.json index c06bd675..a7caf892 100644 --- a/cli/project.json +++ b/cli/project.json @@ -44,15 +44,15 @@ "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4", "Newtonsoft.Json": "9.0.1", "Yavsc": { - "version": "1.0.5-rc21-beta7", + "version": "1.0.5-rc21-beta8", "target": "package" }, "Yavsc.Abstract": { - "version": "1.0.5-rc21-beta7", + "version": "1.0.5-rc21-beta8", "target": "package" }, "Yavsc.Server": { - "version": "1.0.5-rc21-beta7", + "version": "1.0.5-rc21-beta8", "target": "package" }, "Yavsc.Lib.Portable": "1.0.2" diff --git a/rc-num.txt b/rc-num.txt index 81cd254a..03e9fadc 100644 --- a/rc-num.txt +++ b/rc-num.txt @@ -1 +1 @@ -21-beta7 +21-beta8 diff --git a/test/YavscServerFactory.cs b/test/YavscServerFactory.cs new file mode 100644 index 00000000..36b0c9da --- /dev/null +++ b/test/YavscServerFactory.cs @@ -0,0 +1,24 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNet.Hosting.Server; +using Microsoft.AspNet.Http.Features; +using Microsoft.Extensions.Configuration; +using Yavsc.Models; + +namespace Yavsc.Server +{ + public class cliServerFactory : IServerFactory + { + public IFeatureCollection Initialize(IConfiguration configuration) + { + FeatureCollection featureCollection = new FeatureCollection(); + return featureCollection; + } + + public IDisposable Start(IFeatureCollection serverFeatures, Func application) + { + var task = application(serverFeatures); + return task; + } + } +} diff --git a/test/appsettings.json b/test/appsettings.json new file mode 100644 index 00000000..682807de --- /dev/null +++ b/test/appsettings.json @@ -0,0 +1,24 @@ +{ + "Site": { + "Authority": "dev.pschneider.fr", + "Title": "Yavsc dev", + "Slogan": "Yavsc : WIP.", + "Banner": "/images/yavsc.png", + "HomeViewName": "Home", + "FavIcon": "/favicon.ico", + "Icon": "/images/yavsc.png" + }, + "Logging": { + "IncludeScopes": true, + "LogLevel": { + "Default": "Debug", + "System": "Warning", + "Microsoft": "Warning" + } + }, + "Data": { + "DefaultConnection": { + "ConnectionString": "Server=localhost;Port=5432;Database=YavscDev;Username=yavscdev;Password=admin;" + } + } +} diff --git a/test/project.json b/test/project.json index 61738f3d..4e5b8956 100644 --- a/test/project.json +++ b/test/project.json @@ -28,24 +28,23 @@ "defaultNamespace": "Yavsc" }, "dependencies": { - "Yavsc": { - "target": "project" - }, "Newtonsoft.Json": "9.0.1", "xunit": "2.1.0", "xunit.analyzers": "0.9.0", "xunit.assert": "2.1.0", - "xunit.runner.console": "2.1.0", + "xunit.runner.console": "2.4.0-rc.2.build4045", "Microsoft.Dnx.TestHost": "1.0.0-rc1-final", "Microsoft.Dnx.Runtime": "1.0.0-rc1-final", "xunit.runner.dnx": "2.1.0-rc1-build204", - "Yavsc.Abstract": "1.0.5-rc21-beta5", - "Yavsc.Server": "1.0.5-rc21-beta5" + "Yavsc": { + "target": "project" + } }, "frameworks": { "dnx451": {} }, "commands": { "test": "xunit.runner.dnx" - } -} + }, + "userSecretsId": "aspnet5-YavscWeb-a0dadd21-2ced-43d3-96f9-7e504345102f" +} \ No newline at end of file diff --git a/test/src/EMailling.cs b/test/src/EMailling.cs new file mode 100644 index 00000000..19b4a222 --- /dev/null +++ b/test/src/EMailling.cs @@ -0,0 +1,43 @@ +using System; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Hosting.Internal; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.OptionsModel; +using Xunit; +using Xunit.Abstractions; +using Yavsc.Abstract.Manage; +using Yavsc.Lib; +using Yavsc.Services; + +namespace Yavsc.test +{ + + [Collection("EMaillingTeststCollection")] + public class EMaillingTests : IClassFixture + + { + ServerSideFixture _serverFixture; + ITestOutputHelper output; + public EMaillingTests(ServerSideFixture serverFixture, ITestOutputHelper output) + { + this.output = output; + _serverFixture = serverFixture; + } + + [Fact] + public void SendEMailSynchrone() + { + output.WriteLine("SendEMailSynchrone ..."); + EmailSentViewModel mailSentInfo = _serverFixture._mailSender.SendEmailAsync + (_serverFixture._siteSetup.Owner.Name, _serverFixture._siteSetup.Owner.EMail, $"monthly email", "test boby monthly email").Result; + if (mailSentInfo==null) + _serverFixture._logger.LogError("No info on sending"); + else if (!mailSentInfo.Sent) + _serverFixture._logger.LogError($"{mailSentInfo.ErrorMessage}"); + else + _serverFixture._logger.LogInformation($"mailId:{mailSentInfo.MessageId} \nto:{_serverFixture._siteSetup.Owner.Name}"); + Assert.NotNull(mailSentInfo); + output.WriteLine($">>done with {mailSentInfo.EMail} {mailSentInfo.Sent} {mailSentInfo.MessageId} {mailSentInfo.ErrorMessage}"); + } + } +} \ No newline at end of file diff --git a/test/src/NotWorking.cs b/test/src/NotWorking.cs new file mode 100644 index 00000000..e138d143 --- /dev/null +++ b/test/src/NotWorking.cs @@ -0,0 +1,54 @@ +// // NotWorking.cs +// /* +// paul 21/06/2018 10:16 20182018 6 21 +// */ +using System; +using Microsoft.AspNet.Builder; +using Microsoft.Extensions.Localization; +using Microsoft.Extensions.OptionsModel; +using Microsoft.Extensions.PlatformAbstractions; +using Xunit; +using Microsoft.Dnx.Compilation.CSharp; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Configuration; +using Microsoft.AspNet.Builder.Internal; +using Yavsc; +using Microsoft.Extensions.Logging; + +namespace Test +{ + [Collection("Yavsc dropped intents")] + public class NotWorking : BaseTestContext + { + + public void StringLocalizer() + { + var services = new ServiceCollection(); + // IHostingEnvironment env = null; + // IOptions siteSettings; + + services.AddTransient( + svs => PlatformServices.Default.Runtime + ); + beforeCompileContext = YavscMandatory.CreateYavscCompilationContext(); + var prjDir = beforeCompileContext.ProjectContext.ProjectDirectory; + YavscMandatory.ConfigureServices(services, prjDir, out configuration, out provider); + + IApplicationBuilder app = new ApplicationBuilder(provider); + var rtd = app.Build(); + IOptions localOptions = Activator.CreateInstance>(); ; + // TODO build applicationEnvironment + ResourceManagerStringLocalizerFactory strFact = new ResourceManagerStringLocalizerFactory + (applicationEnvironment, localOptions); + IStringLocalizer stringLocalizer = strFact.Create(typeof(NotWorking)); + } + + public void NoDnxEnv() + { + + IOptions localOptions = Activator.CreateInstance>(); + ResourceManagerStringLocalizerFactory strFact = new ResourceManagerStringLocalizerFactory(applicationEnvironment, localOptions); + IStringLocalizer stringLocalizer = strFact.Create(typeof(NotWorking)); + } + } +} diff --git a/test/src/Program.cs b/test/src/Program.cs new file mode 100644 index 00000000..7f9d0d69 --- /dev/null +++ b/test/src/Program.cs @@ -0,0 +1,29 @@ +using Microsoft.AspNet.Hosting; +using Microsoft.Extensions.Logging; +using Yavsc.Lib; +using Yavsc.Services; + +namespace Yavsc.test +{ + public class Program + { + public Program() + { + var host = new WebHostBuilder(); + + var hostengnine = host + .UseEnvironment("Development") + .UseServer("test") + .UseStartup() + .Build(); + + var app = hostengnine.Start(); + var sender = app.Services.GetService(typeof(IEmailSender)) as IEmailSender; + var mailer = app.Services.GetService(typeof(EMailer)) as EMailer; + var loggerFactory = app.Services.GetService(typeof(ILoggerFactory)) as ILoggerFactory; + ILogger logger = loggerFactory.CreateLogger() ; + mailer.SendMonthlyEmail(1,"UserOrientedTemplate"); + logger.LogInformation("Finished"); + } + } +} \ No newline at end of file diff --git a/test/src/ServerSideFixture.cs b/test/src/ServerSideFixture.cs new file mode 100644 index 00000000..49a6a72a --- /dev/null +++ b/test/src/ServerSideFixture.cs @@ -0,0 +1,48 @@ +using System; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Hosting.Internal; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.OptionsModel; +using Yavsc.Lib; +using Yavsc.Services; + +namespace Yavsc.test +{ + public class ServerSideFixture : IDisposable { + public SiteSettings _siteSetup; + public ILogger _logger; + public IApplication _app; + public EMailer _mailer; + public ILoggerFactory _loggerFactory; + public IEmailSender _mailSender; + + public ServerSideFixture() + { + InitServices(); + _logger = _loggerFactory.CreateLogger (); + _logger.LogInformation("ServerSideFixture"); + } + void InitServices() + { + var host = new WebHostBuilder(); + + var hostengnine = host + .UseEnvironment("Development") + .UseServer("test") + .UseStartup() + .Build(); + + _app = hostengnine.Start(); + _mailer = _app.Services.GetService(typeof(EMailer)) as EMailer; + _loggerFactory = _app.Services.GetService(typeof(ILoggerFactory)) as ILoggerFactory; + var siteSetup = _app.Services.GetService(typeof(IOptions)) as IOptions; + _siteSetup = siteSetup.Value; + _mailSender = _app.Services.GetService(typeof(IEmailSender)) as IEmailSender; + } + + public void Dispose() + { + _logger.LogInformation("Disposing"); + } + } +} \ No newline at end of file diff --git a/test/src/Startup.cs b/test/src/Startup.cs new file mode 100644 index 00000000..106671dc --- /dev/null +++ b/test/src/Startup.cs @@ -0,0 +1,100 @@ +using System; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.OptionsModel; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.AspNet.Razor; +using Microsoft.Extensions.PlatformAbstractions; +using Yavsc; +using Yavsc.Models; +using Yavsc.Services; +using Microsoft.Data.Entity; +using Microsoft.AspNet.Authentication; +using Microsoft.Extensions.WebEncoders; +using Yavsc.Lib; + +namespace Yavsc.test +{ + public class Startup + { + public string ConnectionString + { + get ; set; + } + + public static SiteSettings SiteSetup { get; private set; } + public static SmtpSettings SmtpSettup { get; private set; } + public static IConfiguration Configuration { get; set; } + + public static string HostingFullName { get; private set; } + + ILogger logger; + public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) + { + var devtag = env.IsDevelopment()?"D":""; + var prodtag = env.IsProduction()?"P":""; + var stagetag = env.IsStaging()?"S":""; + + HostingFullName = $"{appEnv.RuntimeFramework.FullName} [{env.EnvironmentName}:{prodtag}{devtag}{stagetag}]"; + // Set up configuration sources. + + var builder = new ConfigurationBuilder() + .AddEnvironmentVariables() + .AddJsonFile("appsettings.json") + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); + Configuration = builder.Build(); + ConnectionString = Configuration["Data:DefaultConnection:ConnectionString"]; + AppDomain.CurrentDomain.SetData("YAVSC_CONNECTION", ConnectionString); + } + + public void ConfigureServices (IServiceCollection services) + { + services.AddOptions(); + var siteSettingsconf = Configuration.GetSection("Site"); + services.Configure(siteSettingsconf); + var smtpSettingsconf = Configuration.GetSection("Smtp"); + services.Configure(smtpSettingsconf); + services.AddInstance(typeof(ILoggerFactory), new LoggerFactory()); + services.AddTransient(typeof(IEmailSender), typeof(MailSender)); + services.AddEntityFramework().AddNpgsql().AddDbContext(); + services.AddTransient((s) => new RazorTemplateEngine(s.GetService())); + services.AddLogging(); + services.AddTransient(); + services.AddLocalization(options => + { + options.ResourcesPath = "Resources"; + }); + + services.AddEntityFramework() + .AddNpgsql() + .AddDbContext( + db => db.UseNpgsql(ConnectionString) + ); + services.Configure(options => + { + options.SignInScheme = "Bearer"; + }); + + services.AddTransient(); + + services.AddAuthentication(); + + } + + public void Configure (IApplicationBuilder app, IHostingEnvironment env, + IOptions siteSettings, ILoggerFactory loggerFactory) + { + loggerFactory.AddConsole(Configuration.GetSection("Logging")); + loggerFactory.AddDebug(); + logger = loggerFactory.CreateLogger(); + logger.LogInformation(env.EnvironmentName); + var authConf = Configuration.GetSection("Authentication").GetSection("Yavsc"); + var clientId = authConf.GetSection("ClientId").Value; + var clientSecret = authConf.GetSection("ClientSecret").Value; + + } + + } +} diff --git a/test/src/YavscMandatory.cs b/test/src/YavscMandatory.cs new file mode 100755 index 00000000..a4b895c3 --- /dev/null +++ b/test/src/YavscMandatory.cs @@ -0,0 +1,233 @@ +using System; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Builder.Internal; +using Microsoft.AspNet.Razor; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.PlatformAbstractions; +using Xunit; +using Yavsc; +using Yavsc.Models; +using Yavsc.Services; +using System.Runtime.Versioning; +using Microsoft.AspNet.Mvc.Razor; +using System.Diagnostics; +using Microsoft.Dnx.Compilation.CSharp; +using Microsoft.Extensions.OptionsModel; +using Yavsc.Helpers; +using Microsoft.Data.Entity; +using Xunit.Abstractions; +using System.IO; + +namespace Test +{ + public class BaseTestContext { + protected IApplicationEnvironment applicationEnvironment = null; + protected IServiceProvider serviceProvider = null; + protected IConfigurationRoot configurationRoot; + protected BeforeCompileContext beforeCompileContext; + protected string testprojectAssetPath = "/home/paul/workspace/yavsc/Yavsc"; + + protected IServiceProvider provider; + protected IConfigurationRoot configuration; + } + + [Collection("Yavsc mandatory success story")] + public class YavscMandatory: BaseTestContext + { + private readonly ITestOutputHelper output; + public YavscMandatory(ITestOutputHelper output) + { + this.output = output; + } + + [Fact] + void TestStartNodeJsansitohtml() + { + var procStart = new ProcessStartInfo("env", "/usr/bin/nodejs node_modules/ansi-to-html/bin/ansi-to-html"); + procStart.UseShellExecute = false; + procStart.RedirectStandardInput = true; + procStart.RedirectStandardOutput = true; + procStart.RedirectStandardError = true; + var proc = Process.Start(procStart); + + proc.StandardInput.WriteLine("\x001b[30mblack\x1b[37mwhite"); + proc.StandardInput.Close(); + while (!proc.StandardOutput.EndOfStream) + { + output.WriteLine(proc.StandardOutput.ReadLine()); + } + } + + // actually uses node's ansi-to-html + [Fact] + void AnsiToHtml() + { + var procStart = new ProcessStartInfo("ls", "-l --color=always"); + procStart.UseShellExecute = false; + procStart.RedirectStandardInput = false; + procStart.RedirectStandardOutput = true; + var proc = Process.Start(procStart); + var encoded = AnsiToHtmlEncoder.GetStream(proc.StandardOutput); + using (var reader = new StreamReader(encoded)) + { + var txt = reader.ReadToEnd(); + output.WriteLine(txt); + } + } + + [Fact] + public void ApplicationDbContextExists() + { + var dbc = new ApplicationDbContext(); + Assert.NotNull(dbc.GCMDevices); + } + + [Fact] + public void MvcRazorHostAndParser() + { + string cache = System.IO.Directory.GetCurrentDirectory(); + MvcRazorHost host = new MvcRazorHost(cache); + var parser = host.CreateMarkupParser(); + } + + [Fact] + void HaveDependecyInjection() + { + var services = new ServiceCollection(); + } + + [Fact] + void HaveHost() + { + beforeCompileContext = CreateYavscCompilationContext(); + } + + [Fact] + public void AConfigurationRoot() + { + var builder = new ConfigurationBuilder(); + builder.AddJsonFile(Path.Combine(testprojectAssetPath, "appsettings.json"), false); + builder.AddJsonFile(Path.Combine(testprojectAssetPath, "appsettings.Development.json"), true); + configurationRoot = builder.Build(); + } + + internal static BeforeCompileContext CreateYavscCompilationContext() + { + var projectContext = new ProjectContext(); + projectContext.Name = "Yavsc"; + projectContext.ProjectDirectory = "/home/paul/workspace/yavsc/Yavsc"; + projectContext.ProjectFilePath = "/home/paul/workspace/yavsc/Yavsc/project.json"; + projectContext.TargetFramework = new FrameworkName("DNX", new Version(4, 5, 1)); + projectContext.Configuration = "Development"; + + return new BeforeCompileContext( + null, projectContext, () => null, () => null, () => null); + } + + internal static IConfigurationRoot CreateConfiguration(string prjDir) + { + var builder = new ConfigurationBuilder(); + + builder.AddJsonFile(Path.Combine(prjDir, "appsettings.json"), true); + builder.AddJsonFile(Path.Combine(prjDir, "appsettings.Development.json"), true); + return builder.Build(); + } + + internal static void ConfigureServices + (ServiceCollection serviceCollection, + string prjDir, + out IConfigurationRoot configuration, + out IServiceProvider provider) + { + configuration = CreateConfiguration(prjDir); + + serviceCollection.AddOptions(); + var siteSettingsconf = configuration.GetSection("Site"); + serviceCollection.Configure(siteSettingsconf); + var smtpSettingsconf = configuration.GetSection("Smtp"); + serviceCollection.Configure(smtpSettingsconf); + var locOptions = configuration.GetSection("Localization"); + serviceCollection.Configure(locOptions); + + serviceCollection.AddSingleton(typeof(ILoggerFactory), typeof(LoggerFactory)); + serviceCollection.AddTransient(typeof(IEmailSender), typeof(MailSender)); + serviceCollection.AddTransient(typeof(RazorEngineHost)); + serviceCollection.AddTransient((s) => new RazorTemplateEngine(s.GetService())); + serviceCollection.AddLogging(); + serviceCollection.AddMvcCore(); + serviceCollection.AddLocalization(options => + { + options.ResourcesPath = "Resources"; + }); + var connectionString = configuration["Data:DefaultConnection:ConnectionString"]; + AppDomain.CurrentDomain.SetData("YAVSC_DB_CONNECTION", connectionString); + serviceCollection.AddEntityFramework() + .AddNpgsql() + .AddDbContext( + db => db.UseNpgsql(connectionString) + ); + provider = serviceCollection.BuildServiceProvider(); + } + + + [Fact] + public void ARequestAppDelegate() + { + var services = new ServiceCollection(); + + services.AddTransient( + svs => PlatformServices.Default.Runtime + ); + + HaveHost(); + var prjDir = this.beforeCompileContext.ProjectContext.ProjectDirectory; + ConfigureServices(services, prjDir, out configurationRoot, out serviceProvider); + + IApplicationBuilder app = new ApplicationBuilder(serviceProvider); + var rtd = app.Build(); + + } + + + [Fact] + public void MessageSenderFromLib() + { + ARequestAppDelegate(); + ILoggerFactory factory = ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider); + var dbc = new ApplicationDbContext(); + + IOptions siteOptions = + ActivatorUtilities.GetServiceOrCreateInstance>(serviceProvider); + ; + IOptions smtpOptions = ActivatorUtilities.GetServiceOrCreateInstance>(serviceProvider); + ; + IOptions googleOptions = ActivatorUtilities.GetServiceOrCreateInstance>(serviceProvider); + ; + IEmailSender eSender = new MailSender + (factory, siteOptions, smtpOptions, googleOptions); + } + + [Fact] + public void InitApplicationBuilder() + { + + var services = new ServiceCollection(); + + services.AddTransient( + svs => PlatformServices.Default.Runtime + ); + beforeCompileContext = YavscMandatory.CreateYavscCompilationContext(); + var prjDir = beforeCompileContext.ProjectContext.ProjectDirectory; + YavscMandatory.ConfigureServices(services, prjDir, out configuration, out provider); + + IApplicationBuilder app = new ApplicationBuilder(provider); + app.UseMvc(); + var rtd = app.Build(); + IOptions localOptions = ActivatorUtilities.GetServiceOrCreateInstance>(provider); ; + + } + } +} diff --git a/test/src/YavscWorkInProgress.cs b/test/src/YavscWorkInProgress.cs index cbe2af29..7f6f117e 100644 --- a/test/src/YavscWorkInProgress.cs +++ b/test/src/YavscWorkInProgress.cs @@ -24,7 +24,6 @@ namespace Test public class YavscWorkInProgress : BaseTestContext { - [Fact] public void GitClone() {
+ @Html.DisplayNameFor(model => model.Name) + @Html.DisplayNameFor(model => model.Consent)
+ @Html.DisplayFor(modelItem => item.Name) + @Html.DisplayFor(modelItem => item.Consent)