public async Task WhenTheEventIsInsertedViaCQRSCommand() { var query = new EventSaveCommand(Sut); var handle = new EventSaveHandler(_dbContext); var response = await handle.Handle(query, new System.Threading.CancellationToken()); SutKey = response.Result.EventKey; Assert.IsTrue(SutKey != Guid.Empty); }
public async Task Save() { var logger = testConfig.GetLoggerFactory().CreateLogger <EventSaveHandler>(); EventSaveHandler eventSaveHandler = new EventSaveHandler(testConfig.GetDbContext(), logger); SaveEventCommand newEventcmd = new SaveEventCommand() { EventId = null, EventTranslationId = null, Name = "New event", DateTimeFrom = DateTime.UtcNow, Website = "www", Address = "address", Price = "100.0", Title = "New title", Text = "Text", ShortDescription = "New short descr", LanguageId = 1 }; Tuple <Event, ErrorViewModel> addNewEventResult = await eventSaveHandler.Handle(newEventcmd, new CancellationToken()); Assert.AreEqual("New event", addNewEventResult.Item1.Name); Assert.AreEqual(100, addNewEventResult.Item1.Price); Assert.AreEqual("New title", addNewEventResult.Item1.EventTranslations.First().Title); SaveEventCommand updateEventNewTranslationcmd = new SaveEventCommand() { EventId = 3, EventTranslationId = null, Name = "Update event", DateTimeFrom = DateTime.UtcNow, Website = "www", Address = "address", Price = "200,5", LanguageId = 1, Title = "New title", Text = "Text", ShortDescription = "New short descr" }; Tuple <Event, ErrorViewModel> updateEventNewTranslationResult = await eventSaveHandler.Handle(updateEventNewTranslationcmd, new CancellationToken()); Assert.AreEqual("Update event", updateEventNewTranslationResult.Item1.Name); Assert.AreEqual(200.5, updateEventNewTranslationResult.Item1.Price); Assert.AreEqual("New title", updateEventNewTranslationResult.Item1.EventTranslations.First().Title); Assert.AreEqual(1, updateEventNewTranslationResult.Item1.EventTranslations.Count); SaveEventCommand updateEventWithExistingTranslationCmd = new SaveEventCommand() { EventId = 3, EventTranslationId = updateEventNewTranslationResult.Item1.EventTranslations.First().EventTranslationId, Name = "Update event", DateTimeFrom = DateTime.UtcNow, Website = "www", Address = "address", Price = "200,65", LanguageId = 1, Title = "Update title", Text = "Update Text", ShortDescription = "New short descr" }; Tuple <Event, ErrorViewModel> updateEventWithExistingTranslationResult = await eventSaveHandler.Handle(updateEventWithExistingTranslationCmd, new CancellationToken()); Assert.AreEqual("Update event", updateEventWithExistingTranslationResult.Item1.Name); Assert.AreEqual(200.65, updateEventWithExistingTranslationResult.Item1.Price); Assert.AreEqual("Update title", updateEventWithExistingTranslationResult.Item1.EventTranslations.First().Title); Assert.AreEqual(1, updateEventWithExistingTranslationResult.Item1.EventTranslations.Count); SaveEventCommand updateNotExistingEventCmd = new SaveEventCommand() { EventId = 100, Name = "Update event", DateTimeFrom = DateTime.UtcNow, Address = "address", Price = "200", LanguageId = 1, Title = "Update title", Text = "Update Text", ShortDescription = "New short descr" }; Tuple <Event, ErrorViewModel> updateNotExistingEventResult = await eventSaveHandler.Handle(updateNotExistingEventCmd, new CancellationToken()); Assert.AreEqual((int)AppError.DbRecordNotFound, updateNotExistingEventResult.Item2.ErrorCode); }