public Task <Unit> Handle(CreateSomeDataCommand request, CancellationToken cancellationToken) { try { using (var context = _dbContext) { var businessUser = _businessUserRepositoy.GetByApplicationUserId(request.ApplicationUserId, context); var someData = SomeAggregate.Create(request, businessUser.Id); _someDataWriteRepository.Create(someData, context); context.SaveChanges(); } _eventBus.Publish(new SomeDataCreatedEvent(request.Id, request.FirstName, request.MiddleName, request.LastName, request.Title, request.CreationDate)); return(Unit.Task); } catch (Exception e) { Console.WriteLine(e); throw; } }
public void SaveSomeDataShoulUpdateSomeDataInDatabaseAndSaveChanges() { var updateSomeDataCommand = BuildUpdateSomeDataCommand(); var businessUser = new BusinessUser { Id = Guid.NewGuid(), Gender = "SomeGender", Locale = "SomeLocale", Location = "SomeLocation", Identity = new ApplicationUser { Email = "*****@*****.**" } }; var someDataDb = SomeDataMapper.UpdateSomeDataCommandToPersistanceModel(updateSomeDataCommand); someDataDb.BusinessUserId = businessUser.Id; var someDataDbSet = new List <SomeData> { someDataDb }; var businessUserDb = new List <BusinessUser> { businessUser }; var businessUserMockSet = new MockDbSet <BusinessUser>(businessUserDb); var someDataMockSet = new MockDbSet <SomeData>(someDataDbSet); var contextMock = new Mock <SomeDataContext>(); contextMock.Setup(c => c.SomeData).Returns(someDataMockSet.Object); contextMock.Setup(c => c.BusinessUsers).Returns(businessUserMockSet.Object); var someDataRepository = new SomeDataWriteRepository(contextMock.Object); var updatedSomeData = SomeAggregate.Create(updateSomeDataCommand.SomeDataId, "NewFirstName", "NewMiddleName", "NewLastName", "NewTitle", new Color("#c1d0c3"), DateTime.Now, new FacebookUrl(null), Guid.NewGuid()); someDataRepository.Save(updatedSomeData); var updatedDb = someDataRepository.Get(updateSomeDataCommand.SomeDataId); contextMock.Verify(x => x.SaveChanges(), Times.Once); Assert.Equal(updatedDb.Id, updatedSomeData.Id); Assert.Equal(updatedDb.Color, updatedSomeData.Color); Assert.Equal(updatedDb.CreationDate, updatedSomeData.CreationDate); Assert.Equal(updatedDb.FacebookUrl, updatedSomeData.FacebookUrl); Assert.Equal(updatedDb.FirstName, updatedSomeData.FirstName); Assert.Equal(updatedDb.LastName, updatedSomeData.LastName); Assert.Equal(updatedDb.MiddleName, updatedSomeData.MiddleName); Assert.Equal(updatedDb.Title, updatedSomeData.Title); }
public SomeAggregate BuildSomeAggregate(SomeData someData) { return(SomeAggregate.Create(someData.Id, someData.FirstName, someData.MiddleName, someData.LastName, someData.Title, new Color(someData.Color), someData.CreationDate, new FacebookUrl(someData.FacebookUrl), someData.BusinessUserId)); }
public SomeAggregate BuildSomeAggregate(Guid someDataId) { return(SomeAggregate.Create(someDataId, firstName, middleName, lastName, title, new Color(color), creationDate, new FacebookUrl(facebookUrl), Guid.NewGuid())); }
public static SomeAggregate PersistanceModelToAggregateRoot(Data.Contexts.Models.SomeData persistanceModel) { return(SomeAggregate.Create( persistanceModel.Id, persistanceModel.FirstName, persistanceModel.MiddleName, persistanceModel.LastName, persistanceModel.Title, new Color(persistanceModel.Color), persistanceModel.CreationDate, new FacebookUrl(persistanceModel.FacebookUrl), persistanceModel.BusinessUserId)); }