public void When_Delete_is_called_with_an_Id_then_GetPerformance_on_IPerformanceProcess_is_called_and_the_result_used_to_call_RemovePerformance_on_IPerformanceProcess() { var entity = PerformanceCreator.CreateSingleFuture(); PerformanceProcess .Expect(process => process.GetPerformance(entity.Id)) .Return(entity) .Repeat.Once(); PerformanceProcess .Expect(process => process.RemovePerformance(entity)) .Repeat.Once(); PerformanceProcess.Replay(); var result = Controller.Delete(entity.Id).Result as RedirectToRouteResult; Assert.IsNotNull(result); var routeValues = result.RouteValues; Assert.AreEqual(1, routeValues.Count); foreach (var routeValue in routeValues) { Assert.AreEqual("action", routeValue.Key); Assert.AreEqual("Index", routeValue.Value); } PerformanceProcess.VerifyAllExpectations(); }
public void When_Details_is_called_GetPerformance_on_IPerformanceProcess_is_called_with_the_correct_parameter_and_the_result_is_mapped_with_PerformanceMapper() { var performance = PerformanceCreator.CreateSingleFuture(); PerformanceProcess .Expect(process => process.GetPerformance(performance.Id)) .Return(performance) .Repeat.Once(); PerformanceProcess.Replay(); var performanceDetailsModel = CreatePerformanceDetailsModel(performance.Id); PerformanceMapper .Expect(mapper => mapper.MapToDetail(performance)) .Return(performanceDetailsModel) .Repeat.Once(); PerformanceMapper.Replay(); var result = Controller.Details(performance.Id).Result as ViewResult; Assert.IsNotNull(result); PerformanceProcess.VerifyAllExpectations(); PerformanceMapper.VerifyAllExpectations(); }
public void When_Index_is_called_GetPerformances_on_IPerformanceProcess_is_called_and_the_result_is_mapped_with_PerformanceMapper() { var performances = PerformanceCreator.CreateFutureCollection(); PerformanceProcess .Expect(process => process.GetPerformances()) .Return(performances) .Repeat.Once(); PerformanceProcess.Replay(); var performanceDetailsModelcollection = CreatePerformanceDetailsModelCollection(); PerformanceMapper .Expect(mapper => mapper.Map( Arg <IEnumerable <Performance> > .Matches(articles => performances.All(performance => articles.Any(article => article.Id == performance.Id))))) .Return(performanceDetailsModelcollection) .Repeat.Once(); PerformanceMapper.Replay(); var result = Controller.Future().Result as PartialViewResult; Assert.IsNotNull(result); var model = result.Model as ItemListModel <PerformanceDetailsModel>; Assert.IsNotNull(model); PerformanceProcess.VerifyAllExpectations(); PerformanceMapper.VerifyAllExpectations(); }
public void When_Performance_is_mapped_to_a_PerformanceDetailsModel_then_no_data_is_retrieved_from_process_classes() { PerformanceProcess .Expect(process => process.GetPerformance(Arg <Guid> .Is.Anything)) .Repeat.Never(); PerformanceProcess.Replay(); var entity = PerformanceCreator.CreateSingleFuture(); var result = Mapper.MapToDetail(entity); Assert.AreEqual(entity.Id, result.Id); Assert.AreEqual(entity.CreationDate, result.CreationDate); Assert.AreEqual(entity.ModificationDate, result.ModificationDate); Assert.AreEqual(entity.StartDateTime.Date.ToLocalTime(), result.Date); Assert.AreEqual(entity.StartDateTime.ToLocalTime(), result.StartTime); Assert.AreEqual(entity.EndDateTime.ToLocalTime(), result.EndTime); Assert.AreEqual(entity.City, result.City); Assert.AreEqual(entity.VenueName, result.VenueName); Assert.AreEqual(entity.VenueUri.OriginalString, result.VenueUrl); Assert.AreEqual(entity.Info, result.Info); Assert.AreEqual(entity.Price, result.Price); }
public void When_a_list_of_Performances_is_mapped_to_a_PerformanceDetailsModels_then_no_data_is_retrieved_from_process_classes() { PerformanceProcess .Expect(process => process.GetPerformance(Arg <Guid> .Is.Anything)) .Repeat.Never(); PerformanceProcess.Replay(); var entities = PerformanceCreator.CreateFutureCollection(); var result = Mapper.Map(entities); foreach (var entity in entities) { Assert.IsTrue(result.Items .Single(model => model.Id == entity.Id && model.ModificationDate == entity.ModificationDate && model.CreationDate == entity.CreationDate && model.Date == entity.StartDateTime.Date.ToLocalTime() && model.StartTime == entity.StartDateTime.ToLocalTime() && model.EndTime == entity.EndDateTime.ToLocalTime() && model.City == entity.City && model.Info == entity.Info && model.Price == entity.Price && model.VenueName == entity.VenueName && model.VenueUrl == entity.VenueUri.OriginalString) != null); } }
public void When_Edit_is_called_with_an_Id_then_GetPerformance_on_IPerformanceProcess_is_called_and_the_result_is_mapped_with_PerformanceMapper() { var entity = PerformanceCreator.CreateSingleFuture(); PerformanceProcess .Expect(process => process.GetPerformance(entity.Id)) .Return(entity) .Repeat.Once(); PerformanceProcess.Replay(); var updateModel = CreateUpdatePerformanceModel(Guid.NewGuid()); PerformanceMapper .Expect(mapper => mapper.MapToUpdate( Arg <Performance> .Matches(settings => settings.Id == entity.Id))) .Return(updateModel) .Repeat.Once(); PerformanceMapper.Replay(); var result = Controller.Edit(entity.Id).Result as ViewResult; Assert.IsNotNull(result); var model = result.Model as UpdatePerformanceModel; Assert.IsNotNull(model); PerformanceProcess.VerifyAllExpectations(); PerformanceMapper.VerifyAllExpectations(); }
public void When_Performance_is_mapped_to_a_PerformanceDetailsModel_and_the_venueUri_is_null_then_the_resultUrl_is_stringEmpty() { PerformanceProcess .Expect(process => process.GetPerformance(Arg <Guid> .Is.Anything)) .Repeat.Never(); PerformanceProcess.Replay(); var entity = PerformanceCreator.CreateSingleFuture(); entity.VenueUri = null; var result = Mapper.MapToDetail(entity); Assert.AreEqual(entity.Id, result.Id); Assert.AreEqual(entity.CreationDate, result.CreationDate); Assert.AreEqual(entity.ModificationDate, result.ModificationDate); Assert.AreEqual(entity.StartDateTime.Date.ToLocalTime(), result.Date); Assert.AreEqual(entity.StartDateTime.ToLocalTime(), result.StartTime); Assert.AreEqual(entity.EndDateTime.ToLocalTime(), result.EndTime); Assert.AreEqual(entity.City, result.City); Assert.AreEqual(entity.VenueName, result.VenueName); Assert.AreEqual(string.Empty, result.VenueUrl); Assert.AreEqual(entity.Info, result.Info); Assert.AreEqual(entity.Price, result.Price); }
public void When_GetPerformance_is_called_with_an_Id_and_there_is_no_Performance_in_the_collection_with_that_Id_then_an_InvalidOperationException_is_thrown() { var performances = PerformanceCreator.CreateFutureCollection(); var performanceId = Guid.NewGuid(); BandCatalog .Expect(catalog => catalog.Performances) .Return(performances) .Repeat.Once(); BandCatalog.Replay(); Repository.GetPerformance(performanceId); }
public void When_RemovePerformance_is_called_with_a_Performance_then_the_Performance_is_removed_from_the_collection() { var performance = PerformanceCreator.CreateSingleFuture(); BandCatalog .Expect(catalog => catalog.Remove(performance)) .Repeat.Once(); BandCatalog.Replay(); Repository.RemovePerformance(performance); BandCatalog.VerifyAllExpectations(); }
public void When_RemovePerformance_is_called_with_a_Performance_then_RemovePerformance_on_the_BandRepository_is_called_with_that_Performance() { var performance = PerformanceCreator.CreateSingleFuture(); BandRepository .Expect(repository => repository.RemovePerformance(performance)) .Repeat.Once(); BandRepository.Replay(); Process.RemovePerformance(performance); BandRepository.VerifyAllExpectations(); }
public void When_GetPerformance_is_called_with_a_valid_Guid_then_GetPerformance_on_the_BandRepository_is_called_with_that_Guid() { var performance = PerformanceCreator.CreateSingleFuture(); BandRepository .Expect(repository => repository.GetPerformance(performance.Id)) .Return(performance) .Repeat.Once(); BandRepository.Replay(); Process.GetPerformance(performance.Id); BandRepository.VerifyAllExpectations(); }
public void When_Performance_is_mapped_to_an_UpdatePerformanceModel_then_all_corresponding_fields_are_mapped() { var entity = PerformanceCreator.CreateSingleFuture(); var result = Mapper.MapToUpdate(entity); Assert.AreEqual(entity.Id, result.Id); Assert.AreEqual(entity.StartDateTime.Date.ToLocalTime(), result.Date); Assert.AreEqual(entity.StartDateTime.ToLocalTime(), result.StartTime); Assert.AreEqual(entity.EndDateTime.ToLocalTime(), result.EndTime); Assert.AreEqual(entity.City, result.City); Assert.AreEqual(entity.Info, result.Info); Assert.AreEqual(entity.Price, result.Price); Assert.AreEqual(entity.VenueName, result.VenueName); Assert.AreEqual(entity.VenueUri.OriginalString, result.VenueUrl); }
public void When_UpdatePerformance_is_called_with_a_Performance_then_the_Performance_is_updated_in_the_collection() { var performance = PerformanceCreator.CreateSingleFuture(); BandCatalog .Expect(catalog => catalog.Update(performance)) .Return(performance) .Repeat.Once(); BandCatalog.Replay(); performance = Repository.UpdatePerformance(performance); Assert.IsNotNull(performance); BandCatalog.VerifyAllExpectations(); }
public void When_GetPerformance_is_called_with_an_Id_then_the_Performance_with_the_corresponding_Id_is_retrieved_from_the_collection() { var performances = PerformanceCreator.CreateFutureCollection(); var performanceId = performances.ElementAt(2).Id; BandCatalog .Expect(catalog => catalog.Performances) .Return(performances) .Repeat.Once(); BandCatalog.Replay(); var performance = Repository.GetPerformance(performanceId); Assert.IsNotNull(performance); Assert.AreEqual(performanceId, performance.Id); BandCatalog.VerifyAllExpectations(); }
public void When_GetPastPerformances_is_called_with_a_valid_page_and_pageSize_then_GetPastPerformance_on_the_BandRepository_is_called() { var futurePerformances = PerformanceCreator.CreateFutureCollection(); var pastPerformances = PerformanceCreator.CreatePastCollection(); var performances = pastPerformances.Union(futurePerformances); BandRepository .Expect(repository => repository.GetPastPerformances(Arg <int> .Is.Anything, Arg <int> .Is.Anything)) .Return(performances) .Repeat.Once(); BandRepository.Replay(); var result = Process.GetPastPerformances(0, 32); Assert.AreEqual(performances.Count(), result.Count()); BandRepository.VerifyAllExpectations(); }
public void When_GetPastPerformances_is_called_then_GetAllPastPerformance_on_the_BandRepository_is_called() { var futurePerformances = PerformanceCreator.CreateFutureCollection(); var pastPerformances = PerformanceCreator.CreatePastCollection(); var performances = pastPerformances.Union(futurePerformances); BandRepository .Expect(repository => repository.GetAllPastPerformances()) .Return(performances) .Repeat.Once(); BandRepository.Replay(); var result = Process.GetPastPerformances(); Assert.AreEqual(performances.Count(), result.Count()); BandRepository.VerifyAllExpectations(); }
public void When_Edit_is_called_with_a_model_then_Map_on_PerformanceMapper_is_called_and_the_result_is_used_to_call_UpdatePerformance_on_IPerformanceProcess_with() { var entity = PerformanceCreator.CreateSingleFuture(); PerformanceProcess .Expect(process => process.UpdatePerformance( Arg <Performance> .Matches(settings => settings.Id == entity.Id))) .Return(entity) .Repeat.Once(); PerformanceProcess.Replay(); var updateModel = CreateUpdatePerformanceModel(entity.Id); PerformanceMapper .Expect(mapper => mapper.Map( Arg <UpdatePerformanceModel> .Matches(m => m.City == entity.City && m.VenueName == entity.VenueName), Arg <Guid> .Matches(guid => guid == entity.Id))) .Return(entity) .Repeat.Once(); PerformanceMapper.Replay(); var result = Controller.Edit(entity.Id, updateModel).Result as RedirectToRouteResult; Assert.IsNotNull(result); var routeValues = result.RouteValues; Assert.AreEqual(1, routeValues.Count); foreach (var routeValue in routeValues) { Assert.AreEqual("action", routeValue.Key); Assert.AreEqual("Index", routeValue.Value); } PerformanceProcess.VerifyAllExpectations(); PerformanceMapper.VerifyAllExpectations(); }
public void When_GetAllPastPerformances_is_called_then_all_past_Performances_are_retrieved_from_the_collection() { var futurePerformances = PerformanceCreator.CreateFutureCollection(); var pastPerformances = PerformanceCreator.CreatePastCollection(); var performances = pastPerformances.Union(futurePerformances); BandCatalog .Expect(catalog => catalog.Performances) .Return(performances) .Repeat.Once(); BandCatalog.Replay(); var result = Repository.GetAllPastPerformances(); Assert.IsNotNull(result); Assert.AreEqual(pastPerformances.Count(), result.Count()); Assert.AreEqual(pastPerformances.First(), result.First()); BandCatalog.VerifyAllExpectations(); }
public void When_UpdatePerformance_is_mapped_to_a_Performance_and_the_VenueUrl_is_null_then_all_fields_are_mapped_correctly_and_VenueUri_in_the_result_is_null() { var startDateTime = DateTime.Now.AddDays(37); var endDateTime = startDateTime.AddHours(4); var entity = PerformanceCreator.CreateSingleFuture(); PerformanceProcess .Expect(process => process.GetPerformance(entity.Id)) .Return(entity) .Repeat.Once(); PerformanceProcess.Replay(); var updateModel = new UpdatePerformanceModel { Id = entity.Id, Date = startDateTime.Date, StartTime = startDateTime, EndTime = endDateTime, City = "City", Info = "Info", Price = DateTime.UtcNow.Ticks, VenueUrl = null, }; var result = Mapper.Map(updateModel, entity.Id); Assert.AreEqual(entity.Id, result.Id, "Id not correct"); Assert.AreEqual(updateModel.Date.ToString("ddMMyyyy", CultureInfo.InvariantCulture), result.StartDateTime.ToString("ddMMyyyy", CultureInfo.InvariantCulture), "StartDateTime not correct"); Assert.AreEqual(updateModel.StartTime.ToString("HHmm", CultureInfo.InvariantCulture), result.StartDateTime.ToString("HHmm", CultureInfo.InvariantCulture), "StartDateTime not correct"); Assert.AreEqual(updateModel.EndTime.ToString("HHmm", CultureInfo.InvariantCulture), result.EndDateTime.ToString("HHmm", CultureInfo.InvariantCulture), "EndDateTime not correct"); Assert.AreEqual(updateModel.City, result.City, "City not correct"); Assert.AreEqual(updateModel.Info, result.Info, "Info not correct"); Assert.AreEqual(updateModel.Price, result.Price, "Proce not correct"); Assert.AreEqual(updateModel.VenueName, result.VenueName, "VenueName not correct"); Assert.AreEqual(null, result.VenueUri, "VenueUri not correct"); PerformanceProcess.VerifyAllExpectations(); }
public void When_GetPerformances_is_called_then_the_specified_number_of_future_Performances_are_retrieved_from_the_collection() { const int page = 0; const int pageSize = 3; var futurePerformances = PerformanceCreator.CreateFutureCollection(); var pastPerformances = PerformanceCreator.CreatePastCollection(); var performances = pastPerformances.Union(futurePerformances); BandCatalog .Expect(catalog => catalog.Performances) .Return(performances) .Repeat.Once(); BandCatalog.Replay(); var result = Repository.GetFuturePerformances(page, pageSize); Assert.IsNotNull(result); Assert.AreEqual(pageSize, result.Count()); Assert.AreEqual(futurePerformances.First(), result.First()); BandCatalog.VerifyAllExpectations(); }