public void Teststtt() { var messageFactory = new MessageFactory(typeof(EnvelopeSerializer_Event), typeof(EnvelopeSerializer_Child_Event)); var identityFactory = new IdentityFactory(typeof(EnvelopeSerializer_Id)); var serializer = new ProtobufSerializer(); serializer.RegisterMessages(messageFactory.MessageDefinitions); serializer.RegisterIdentities(identityFactory.IdentityDefinitions); var message1 = new EnvelopeSerializer_Event() { Rate = 0.7, Title = "Muahaha!" }; var packetSerializer = new PacketSerializer(serializer, messageFactory.TagToTypeResolver); var packet = new PacketBuilder(messageFactory.TypeToTagResolver, packetSerializer) .AddMessage(message1) .Build(); var bytes = packet.Serialize(); var back = new Packet(packetSerializer, bytes); var evnt = (EnvelopeSerializer_Event)back.Envelopes.First().Message; Assert.That(evnt.Rate, Is.EqualTo(message1.Rate)); Assert.That(evnt.Title, Is.EqualTo(message1.Title)); }
public async Task GetCatalogDetail_With_Empty_CatalogId_ShouldBe_Invalid(int pageIndex, int pageSize) { var request = new GetCatalogDetailRequest { CatalogId = IdentityFactory.Create <CatalogId>(Guid.Empty), SearchCatalogCategoryRequest = new GetCatalogDetailRequest.CatalogCategorySearchRequest { PageIndex = pageIndex, PageSize = pageSize } }; await this._testFixture.ExecuteValidationTest(request, result => { result.ShouldHaveValidationErrorFor(x => x.CatalogId); if (pageIndex < 0 || pageIndex == int.MaxValue) { result.ShouldHaveValidationErrorFor(x => x.SearchCatalogCategoryRequest.PageIndex); } if (pageSize < 0 || pageSize == int.MaxValue) { result.ShouldHaveValidationErrorFor(x => x.SearchCatalogCategoryRequest.PageSize); } }); }
public void Teststtt() { var messageFactory = new MessageFactory(typeof(TransitionEnvelopeSerializer_Event), typeof(TransitionEnvelopeSerializer_Child_Event)); var identityFactory = new IdentityFactory(typeof(TransitionEnvelopeSerializer_Id)); var serializer = new ProtobufSerializer(); serializer.RegisterMessages(messageFactory.MessageDefinitions); serializer.RegisterIdentities(identityFactory.IdentityDefinitions); var header = new TransitionEnvelopeDataHeader() { MessageTags = new[] { Guid.Parse("74467730-33c0-418a-bd83-963258ce6fa9"), Guid.Parse("f55856e9-66b3-4fd4-9f6a-de9c2606a692") } }; var message1 = new TransitionEnvelopeSerializer_Event() { Rate = 0.7, Title = "Muahaha!" }; var memory = new MemoryStream(); serializer.Model.SerializeWithLengthPrefix(memory, header, header.GetType(), PrefixStyle.Base128, 0); serializer.Model.SerializeWithLengthPrefix(memory, message1, message1.GetType(), PrefixStyle.Fixed32, 0); memory.Position = 0; var back = serializer.Model.DeserializeWithLengthPrefix(memory, null, header.GetType(), PrefixStyle.Base128, 0, null); var backMessage1 = serializer.Model.DeserializeWithLengthPrefix(memory, null, typeof(TransitionEnvelopeSerializer_Event), PrefixStyle.Fixed32, 0, null); }
public async Task Remove_CatalogCategory_Successfully() { var catalog = Catalog.Create(this.Fixture.Create <string>()); var catalogs = new List <Catalog> { catalog }; this._mockDbContext .Setup(x => x.Set <Catalog>()) .ReturnsDbSet(catalogs); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, this.Fixture.Create <string>()); var command = new RemoveCatalogCategoryCommand { CatalogId = catalog.CatalogId, CatalogCategoryId = catalogCategory.CatalogCategoryId }; IRequestHandler <RemoveCatalogCategoryCommand> handler = new CommandHandler(this.MockRepositoryFactory.Object, this._validator); await handler.Handle(command, this.CancellationToken); this._mockDbContext.Verify(x => x.Update(catalog), Times.Once); }
public void IdentityFactory_FromGuid_BuildsCorrectTypes() { // Configured once for the app domain, but could be inferred from the // identity type associated to a specific object. IdentityFactory.IdentityType = IdentityFactoryTypes.Guid; // Simulates loading an existing identity value from a database, // but would never actually reference the Guid type. var companyID = IdentityFactory.GetIdentity(Guid.NewGuid()); var employee = new Employee() { ID = IdentityFactory.GetNewIdentity(), CompanyID = companyID, Name = "Tom Petty", Age = 57 }; var repository = new InMemoryRepository <Employee>(); repository.Save(employee); var savedEmployee = repository.Load(employee.ID).FirstOrDefault(); Assert.AreEqual(employee.ID, savedEmployee.ID); Assert.AreEqual(employee.CompanyID, savedEmployee.CompanyID); Assert.IsTrue(employee.ID is GuidIdentity); Assert.IsTrue(employee.CompanyID is GuidIdentity); }
public void Configuration(IAppBuilder app) { //Issuer – a unique identifier for the entity that issued the token (not to be confused with Entity Framework’s entities) //Secret – a secret key used to secure the token and prevent tampering var issuer = ConfigurationManager.AppSettings["issuer"]; var secret = TextEncodings.Base64Url.Decode(ConfigurationManager.AppSettings["secret"]); //Important note: The life-cycle of object instance is per-request. As soon as the request is complete, the instance is cleaned up. var dbContext = (UnitOfWork) new UnitOfWorkFactory().Create(); app.CreatePerOwinContext <UnitOfWork>(() => dbContext); app.CreatePerOwinContext(() => IdentityFactory.CreateUserManager(dbContext)); //Enable bearer authentication - this code adds JWT bearer authentication to the OWIN pipeline app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions { AuthenticationMode = AuthenticationMode.Active, AllowedAudiences = new[] { "Any" }, IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[] { new SymmetricKeyIssuerSecurityTokenProvider(issuer, secret) } }); //expose an OAuth endpoint so that the client can request a token (by passing a user name and password) app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions { AllowInsecureHttp = true, //for debugging/PoC. Later disable insecure access TokenEndpointPath = new PathString("/oauth2/token"), //End-point Provider = new CustomOAuthProvider(), //use custom provider and formatter AccessTokenFormat = new MSIdentityJwtFormat() }); }
protected override void Load(ContainerBuilder builder) { builder.RegisterType(typeof(AppUserManager)).As(typeof(IApplicationUserManager)).InstancePerRequest(); builder.RegisterType(typeof(AppRoleManager)).As(typeof(IApplicationRoleManager)).InstancePerRequest(); builder.RegisterType(typeof(AppSignInManager)).As(typeof(IApplicationSignInManager)).InstancePerRequest(); builder.RegisterType(typeof(ApplicationAuthenticationManager)).As(typeof(IApplicationAuthenticationManager)).InstancePerRequest(); builder.RegisterType(typeof(ApplicationIdentityUser)).As(typeof(IUser <int>)).InstancePerRequest(); builder.Register(b => b.Resolve <IEntitiesContext>() as DbContext).InstancePerRequest(); builder.Register(b => IdentityFactory.CreateUserManager(b.Resolve <IEntitiesContext>() as ApplicationDbContext, Startup.DataProtectionProvider)).InstancePerRequest(); builder.Register(b => IdentityFactory.CreateRoleManager(b.Resolve <IEntitiesContext>() as ApplicationDbContext)); builder.Register(b => IdentityFactory.CreateSignInManager(b.Resolve <ApplicationUserManager>(), HttpContext.Current.GetOwinContext().Authentication)).InstancePerRequest(); builder.Register(b => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest(); //builder.RegisterType(typeof(ApplicationRole)).As(typeof(IRole<int>)).InstancePerRequest(); //builder.Register(b => //{ // var manager = IdentityFactory.CreateUserManager(b.Resolve<DbContext>()); // if (Startup.DataProtectionProvider != null) // { // manager.UserTokenProvider = // new DataProtectorTokenProvider<ApplicationIdentityUser, int>( // Startup.DataProtectionProvider.Create("ASP.NET Identity")); // } // return manager; //}).InstancePerHttpRequest(); }
public override TIdentity Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { return(IdentityFactory.Create <TIdentity>(reader.GetGuid())); }
private Product(string productCode, string productName) : this(IdentityFactory.Create <ProductId>(), productCode, productName) { this.AddUncommittedEvent(new ProductCreated { ProductId = this.Id, ProductCode = this.Code }); }
public void should_correctly_handle_duplicate_registration_of_the_same_identity() { var factory = new IdentityFactory(typeof(IdentityFactory_Duplicate_ProcessId), typeof(IdentityFactory_Duplicate_ProcessId)); Assert.That(factory.IdentityDefinitions.Count(), Is.EqualTo(1)); Assert.That(factory.IdentityDefinitions.First().Type, Is.EqualTo(typeof(IdentityFactory_Duplicate_ProcessId))); Assert.That(factory.IdentityDefinitions.First().Tag, Is.EqualTo(Guid.Parse("30666dff-550b-4e0b-91bf-9f09f82e42c8"))); }
public void Create_CatalogProduct_With_Null_Of_ProductId_ShouldThrowException() { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, this._fixture.Create <string>()); Should.Throw <DomainException>(() => catalogCategory.CreateCatalogProduct(null, this._fixture.Create <string>())); }
public static void CreateAdminUsers(AkureTrainingDbContext context) { const string password = "******"; var users = new string[] { "*****@*****.**", "*****@*****.**", "*****@*****.**", }; var applicationRoleManager = IdentityFactory.CreateRoleManager(context); var applicationUserManager = IdentityFactory.CreateUserManager(context); Array.ForEach(users, customerID => { IdentityResult identityResult; var user = applicationUserManager.FindByNameAsync(customerID).Result; if (user == null) { user = new ApplicationIdentityUser { UserName = customerID, Email = customerID }; identityResult = applicationUserManager.CreateAsync(user, password).Result; if (!identityResult.Succeeded) { identityResult = applicationUserManager.SetLockoutEnabledAsync(user.Id, false).Result; } } var roleResult = applicationRoleManager.RoleExistsAsync("ADMIN"); if (!roleResult.Result) { identityResult = applicationRoleManager.CreateAsync(new ApplicationIdentityRole { Name = "ADMIN" }).Result; } var isInRole = applicationUserManager.IsInRoleAsync(user.Id, "ADMIN"); if (user != null && !isInRole.Result) { identityResult = applicationUserManager.AddToRoleAsync(user.Id, "ADMIN").Result; } //validate Email if (user != null) { var token = applicationUserManager.GenerateEmailConfirmationToken(user.Id); applicationUserManager.ConfirmEmail(user.Id, token); } }); }
public void CatalogCategory_Change_DisplayName_ToEmpty_ShouldThrowException(string creationName) { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, creationName); Should.Throw <DomainException>(() => catalogCategory.ChangeDisplayName(string.Empty)); }
public void Catalog_Create_Chain_Of_CatalogCategories_Successfully() { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryIdLv1 = IdentityFactory.Create <CategoryId>(); var categoryIdLv2 = IdentityFactory.Create <CategoryId>(); var categoryIdLv3 = IdentityFactory.Create <CategoryId>(); var catalogCategoryLv1 = catalog.AddCategory(categoryIdLv1, this._fixture.Create <string>()); var catalogCategoryLv2 = catalog.AddCategory(categoryIdLv2, this._fixture.Create <string>(), catalogCategoryLv1); var catalogCategoryLv3 = catalog.AddCategory(categoryIdLv3, this._fixture.Create <string>(), catalogCategoryLv2); var catalogCategories = new List <CatalogCategory> { catalogCategoryLv1, catalogCategoryLv2, catalogCategoryLv3 }; catalog .Categories .Except(catalogCategories) .Any() .ShouldBeFalse(); var roots = catalog.FindCatalogCategoryRoots(); roots.ShouldHaveSingleItem(); var descendantsOfLv1 = catalog.GetDescendantsOfCatalogCategory(catalogCategoryLv1); descendantsOfLv1 .Except(catalogCategories) .Any() .ShouldBeFalse(); var descendantsOfLv2 = catalog.GetDescendantsOfCatalogCategory(catalogCategoryLv2); descendantsOfLv2 .Except(catalogCategories.Where(x => x != catalogCategoryLv1)) .Any() .ShouldBeFalse(); var descendantsOfLv3 = catalog.GetDescendantsOfCatalogCategory(catalogCategoryLv3); descendantsOfLv3 .Except(catalogCategories.Where(x => x != catalogCategoryLv1 && x != catalogCategoryLv2)) .Any() .ShouldBeFalse(); }
public void Create_CatalogProduct_Without_DisplayName_ShouldThrowException() { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, this._fixture.Create <string>()); var productId = IdentityFactory.Create <ProductId>(); Should.Throw <DomainException>(() => catalogCategory.CreateCatalogProduct(productId, string.Empty)); }
public void CatalogCategory_Change_DisplayName_Successfully(string creationName, string changeToName) { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog .AddCategory(categoryId, creationName) .ChangeDisplayName(changeToName); catalogCategory.DisplayName.ShouldBe(changeToName); }
public void Remove_Null_Of_CatalogProduct_ShouldThrowException() { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, this._fixture.Create <string>()); var catalogProduct = catalogCategory.Products.FirstOrDefault(); Should.Throw <DomainException>(() => catalogCategory.RemoveCatalogProduct(catalogProduct)); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var stringValue = value as string; if (!string.IsNullOrEmpty(stringValue) && Guid.TryParse(stringValue, out var guid)) { return(IdentityFactory.Create <TIdentity>(guid)); } return(base.ConvertFrom(context, culture, value)); }
public void Remove_CatalogProduct_Successfully() { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, this._fixture.Create <string>()); var productId = IdentityFactory.Create <ProductId>(); var catalogProduct = catalogCategory.CreateCatalogProduct(productId, this._fixture.Create <string>()); catalogCategory.RemoveCatalogProduct(catalogProduct); catalogCategory.Products.ShouldBeEmpty(); }
public void Catalog_NotFound_ShouldBeInvalid() { var command = new RemoveCatalogCategoryCommand { CatalogId = (CatalogId)Guid.Empty, CatalogCategoryId = IdentityFactory.Create <CatalogCategoryId>() }; var result = this._validator.TestValidate(command); result.ShouldHaveValidationErrorFor(x => x.CatalogId); result.ShouldNotHaveValidationErrorFor(x => x.CatalogCategoryId); }
private Transaction BuildTransactionInfo(TransactionInfo transactionInfo) { var transaccionId = IdentityFactory.CreateIdentity().NewSequentialTransactionIdentity(); return(new Transaction { TransactionId = transaccionId.TransactionId, TransactionDate = transaccionId.TransactionDate, TransactionOrigen = transactionInfo.TipoTransaccion, TransactionType = transactionInfo.TipoTransaccion, ModifiedBy = transactionInfo.ModificadoPor, }); }
private CatalogProduct InitCatalogProduct(string creationName) { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, this._fixture.Create <string>()); var productId = IdentityFactory.Create <ProductId>(); var catalogProduct = catalogCategory .CreateCatalogProduct(productId, creationName); return(catalogProduct); }
//Create [email protected] with password=Admin@123456 in the Admin role public void InitializeIdentityForEF(AspnetIdentityWithOnionContext db) { // This is only for testing purpose const string name = "*****@*****.**"; const string password = "******"; const string roleName = "Admin"; var applicationRoleManager = IdentityFactory.CreateRoleManager(db); var applicationUserManager = IdentityFactory.CreateUserManager(db); //Create Role Admin if it does not exist var role = applicationRoleManager.FindByName(roleName); if (role == null) { role = new ApplicationIdentityRole { Name = roleName }; applicationRoleManager.Create(role); } var user = applicationUserManager.FindByName(name); if (user == null) { user = new ApplicationIdentityUser { UserName = name, Email = name }; applicationUserManager.Create(user, password); applicationUserManager.SetLockoutEnabled(user.Id, false); } // Add user admin to Role Admin if not already added var rolesForUser = applicationUserManager.GetRoles(user.Id); if (!rolesForUser.Contains(role.Name)) { applicationUserManager.AddToRole(user.Id, role.Name); } var context = new AspnetIdentityWithOnionContext("name=AppContext", new DebugLogger()); var image = new Image { Path = "http://lorempixel.com/400/200/" }; context.Set <Image>().Add(image); for (var i = 0; i < 100; i++) { context.Set <Product>().Add(new Product { Name = "My Product", Description = "My Product", Image = image }); } context.SaveChanges(); }
public void Create_CatalogProduct_Successfully() { var catalog = Catalog.Create(this._fixture.Create <string>()); var categoryId = IdentityFactory.Create <CategoryId>(); var catalogCategory = catalog.AddCategory(categoryId, this._fixture.Create <string>()); var productId = IdentityFactory.Create <ProductId>(); var catalogProduct = catalogCategory.CreateCatalogProduct(productId, this._fixture.Create <string>()); catalogCategory.Products.ShouldContain(catalogProduct); catalogProduct.ShouldNotBeNull(); catalogProduct.CatalogCategory.ShouldBe(catalogCategory); }
public void Not_Found_Catalog_ShouldBeInvalid() { var command = new UpdateCatalogCategoryCommand { CatalogId = IdentityFactory.Create <CatalogId>(), CatalogCategoryId = IdentityFactory.Create <CatalogCategoryId>(), DisplayName = this.Fixture.Create <string>() }; var result = this._validator.TestValidate(command); result.ShouldHaveValidationErrorFor(x => x.CatalogId); result.ShouldNotHaveValidationErrorFor(x => x.CatalogCategoryId); result.ShouldNotHaveValidationErrorFor(x => x.DisplayName); }
public void Command_With_NotFound_Catalog_ShouldBeInvalid() { var command = new CreateCatalogCategoryCommand { CatalogId = IdentityFactory.Create <CatalogId>(), CategoryId = this._category.CategoryId, DisplayName = this._category.DisplayName }; var result = this._validator.TestValidate(command); result.ShouldHaveValidationErrorFor(x => x.CatalogId); result.ShouldNotHaveValidationErrorFor(x => x.CategoryId); result.ShouldNotHaveValidationErrorFor(x => x.DisplayName); }
public MachineContext(IEnumerable <Type> messageTypes, IEnumerable <Type> identityTypes, IDictionary <String, IRouter> routers) { _messageFactory = new MessageFactory(messageTypes); _identityFactory = new IdentityFactory(identityTypes); _serializer = new ProtobufSerializer(); _serializer.RegisterMessages(_messageFactory.MessageDefinitions); _serializer.RegisterIdentities(_identityFactory.IdentityDefinitions); _packetSerializer = new PacketSerializer(_serializer, _messageFactory.TagToTypeResolver); _routerFactory = new RouterFactory(routers); _zeromqContext = new ZMQ.Context(2); }
public async Task Should_Throw_ValidationException_When_Request_Is_Invalid(int pageIndex, int pageSize) { var request = new GetCatalogDetailRequest { CatalogId = IdentityFactory.Create <CatalogId>(Guid.Empty), SearchCatalogCategoryRequest = new GetCatalogDetailRequest.CatalogCategorySearchRequest { PageIndex = pageIndex, PageSize = pageSize } }; await Should.ThrowAsync <ValidationException>(async() => await this._testFixture.ExecuteTestRequestHandler <GetCatalogDetailRequest, GetCatalogDetailResult>(request, result => {})); }
public void CatalogProduct_NotFound_ShouldBe_Invalid() { var command = new RemoveCatalogProductCommand { CatalogId = this._catalog.CatalogId, CatalogCategoryId = this._catalogCategory.CatalogCategoryId, CatalogProductId = IdentityFactory.Create <CatalogProductId>() }; var result = this._validator.TestValidate(command); result.ShouldHaveValidationErrorFor(x => x.CatalogProductId); result.ShouldNotHaveValidationErrorFor(x => x.CatalogId); result.ShouldNotHaveValidationErrorFor(x => x.CatalogCategoryId); }
public async Task Should_GetCatalogDetail_Successfully_Even_NotFound_Catalog() { var request = new GetCatalogDetailRequest { CatalogId = IdentityFactory.Create <CatalogId>() }; await this._testFixture.ExecuteTestRequestHandler <GetCatalogDetailRequest, GetCatalogDetailResult>(request, result => { result.ShouldNotBeNull(); result.TotalOfCatalogCategories.ShouldBe(0); result.CatalogDetail.ShouldNotBeNull(); result.CatalogDetail.Id.ShouldBeNull(); result.CatalogDetail.DisplayName.ShouldBeNull(); result.CatalogCategories.ShouldBeNull(); }); }