Given_no_products_currently_being_used_when_checking_for_product_clashes_then_none_are_found() { // Arrange var fixture = new SafeFixture(); var spotToCheckForClashes = fixture.Create <Spot>(); var infoForAllSpots = new Dictionary <Guid, SpotInfo> { [spotToCheckForClashes.Uid] = new SpotInfo { Uid = spotToCheckForClashes.Uid } }; var labrat = new ProductClashChecker(enabled: true); // Act IEnumerable <Spot> result = labrat.GetProductClashesForMultipleSpots( new List <Spot>(1) { spotToCheckForClashes }, new List <Spot>(0), infoForAllSpots, ClashCodeLevel.Child ); // Assert _ = result.Should().BeEmpty(becauseArgs: null); }
Given_an_invalid_clash_code_level_when_checking_for_a_product_clash_then_an_exception_is_thrown() { const ClashCodeLevel invalidValue = (ClashCodeLevel)Int32.MinValue; // Assert var ex = Assert.Throws <InvalidOperationException>(() => { // Arrange var fixture = new SafeFixture(); var spotToCheckForClashes = fixture.Create <Spot>(); var infoForAllSpots = new Dictionary <Guid, SpotInfo> { [spotToCheckForClashes.Uid] = new SpotInfo { Uid = spotToCheckForClashes.Uid } }; var labrat = new ProductClashChecker(enabled: true); // Act IEnumerable <Spot> result = labrat.GetProductClashesForSingleSpot( spotToCheckForClashes, new List <Spot>(0), infoForAllSpots, invalidValue ); }); _ = ex.Message.Should().Contain(invalidValue.ToString(), becauseArgs: null); }
public void Init() { _fixture = new SafeFixture(); _fakeSpotRepository = new Mock <ISpotRepository>(); _fakeCampaignRepository = new Mock <ICampaignRepository>(); _fakeProductRepository = new Mock <IProductRepository>(); _fakeClashRepository = new Mock <IClashRepository>(); _fakeBreakRepository = new Mock <IBreakRepository>(); _fakeScheduleRepository = new Mock <IScheduleRepository>(); _fakeAuditEventRepository = new Mock <IAuditEventRepository>(); _fakeDataChangeValidator = new Mock <IDataChangeValidator>(); _mapper = AutoMapperInitializer.Initialize(AutoMapperConfig.SetupAutoMapper); _controller = new SpotsController( _fakeSpotRepository.Object, _fakeBreakRepository.Object, _fakeScheduleRepository.Object, _fakeDataChangeValidator.Object, _fakeAuditEventRepository.Object, new SpotModelCreator(_fakeCampaignRepository.Object, _fakeProductRepository.Object, _fakeClashRepository.Object, _mapper), _mapper ); _controller.Request = new HttpRequestMessage(); _controller.Request.SetConfiguration(new HttpConfiguration()); }
public void DeleteSpotsByDateRangeAndSalesAreaDeletesSpots() { // Arrange var fixture = new SafeFixture(); var breakDateTime = new DateTime(2019, 12, 31, 10, 30, 0); var salesAreaName = fixture.Create <string>(); var fakeBreaks = fixture.CreateMany <Break>(3).ToList(); var fakeSpots = fixture.CreateMany <Spot>(3).ToList(); fakeBreaks.ForEach(aBreak => aBreak.ScheduledDate = breakDateTime.AddMinutes(-15)); fakeBreaks.ForEach(aBreak => aBreak.ScheduledDate = aBreak.ScheduledDate.AddMinutes(15)); fakeBreaks.ForEach(aBreak => aBreak.SalesArea = salesAreaName); fakeSpots.ForEach(spot => spot.ExternalBreakNo = fakeBreaks[0].ExternalBreakRef); fakeSpots[2].ExternalBreakNo = fakeBreaks[1].ExternalBreakRef; fakeSpots.ForEach(spot => spot.SalesArea = salesAreaName); var expectedSpotIds = fakeSpots .Where(spot => spot.ExternalBreakNo == fakeBreaks[0].ExternalBreakRef); _ = _fakeBreakRepository .Setup(r => r.Search(It.IsAny <DateTimeRange>(), It.IsAny <IReadOnlyCollection <string> >())) .Returns(fakeBreaks); _ = _fakeSpotRepository .Setup(r => r.FindByExternalBreakNumbers(It.IsAny <IReadOnlyCollection <string> >())) .Returns(expectedSpotIds); // Act var result = _controller.Delete( breakDateTime, breakDateTime.AddMinutes(10), new List <string> { salesAreaName } ); // Assert Assert.IsInstanceOf <OkResult>(result); _fakeBreakRepository.Verify( m => m.Search(It.IsAny <DateTimeRange>(), It.IsAny <IReadOnlyCollection <string> >()), Times.Once); _fakeSpotRepository.Verify( m => m.FindByExternalBreakNumbers(It.IsAny <IReadOnlyCollection <string> >()), Times.Once); _fakeSpotRepository.Verify( m => m.Delete(It.IsAny <IEnumerable <Guid> >()), Times.Once ); }
Given_product_clash_checking_is_not_enabled_when_checking_for_product_clashes_then_none_are_found() { // Arrange var labrat = new ProductClashChecker(enabled: false); var fixture = new SafeFixture(); // Act IEnumerable <Spot> result = labrat.GetProductClashesForSingleSpot( fixture.Create <Spot>(), new List <Spot>(0), new Dictionary <Guid, SpotInfo>(0), ClashCodeLevel.Child ); // Assert _ = result.Should().BeEmpty(becauseArgs: null); }
Given_a_similar_child_product_is_already_used_when_searching_for_a_child_clash_then_a_clash_is_found() { // Arrange var fixture = new SafeFixture(); var spotToCheckForClashes = fixture.Create <Spot>(); var nonClashingSpot = fixture.Create <Spot>(); var productCodeThatWillClash = fixture.Create <string>(); var infoForAllSpots = new Dictionary <Guid, SpotInfo> { [spotToCheckForClashes.Uid] = new SpotInfo { Uid = spotToCheckForClashes.Uid, ProductClashCode = productCodeThatWillClash }, [nonClashingSpot.Uid] = new SpotInfo { Uid = nonClashingSpot.Uid } }; var labrat = new ProductClashChecker(enabled: true); // Act IEnumerable <Spot> result = labrat.GetProductClashesForMultipleSpots( new List <Spot>(1) { spotToCheckForClashes }, new List <Spot> { spotToCheckForClashes, nonClashingSpot }, infoForAllSpots, ClashCodeLevel.Child ); // Assert _ = result.Should().NotBeEmpty(becauseArgs: null); }
Given_a_legacy_scenario_with_a_null_DateCreated_when_getting_all_scenarios_then_the_DateCreated_is_null() { // Arrange Fixture fixture = new SafeFixture(); var fakeRunRepository = new Mock <IRunRepository>(); var fakeScenarioRepository = new Mock <IScenarioRepository>(); var fakePassRepository = new Mock <IPassRepository>(); var fakeTenantSettingsRepository = new Mock <ITenantSettingsRepository>(); var fakeIdentityGeneratorResolver = new Mock <IIdentityGeneratorResolver>(); var fakePassInspectorService = new Mock <IPassInspectorService>(); IMapper mapper = AutoMapperInitializer.Initialize(Configuration.AutoMapperConfig.SetupAutoMapper); IEnumerable <Pass> fakePasses = fixture.CreateMany <Pass>(1); IEnumerable <PassReference> fakePassReferences = fixture .Build <PassReference>() .With(p => p.Id, fakePasses.First().Id) .CreateMany(1); IEnumerable <Scenario> scenarioWithDateModifiedNull = fixture .Build <Scenario>() .Without(p => p.DateCreated) .With(p => p.Passes, fakePassReferences.ToList()) .CreateMany(1); TenantSettings fakeTenantSettings = fixture .Build <TenantSettings>() .With(p => p.DefaultScenarioId, Guid.NewGuid()) .Create(); _ = fakePassRepository .Setup(m => m.FindByIds(It.IsAny <IEnumerable <int> >())) .Returns(fakePasses); _ = fakeScenarioRepository .Setup(m => m.GetAll()) .Returns(scenarioWithDateModifiedNull); _ = fakeTenantSettingsRepository .Setup(m => m.Get()) .Returns(fakeTenantSettings); using (var scenariosController = new ScenariosController( fakeRunRepository.Object, fakeScenarioRepository.Object, fakePassRepository.Object, fakeTenantSettingsRepository.Object, fakeIdentityGeneratorResolver.Object, mapper, null, null, fakePassInspectorService.Object )) { // Act IEnumerable <ScenarioModel> result = scenariosController.GetAll(); // Assert Assert.That(result.First().DateCreated, Is.Null); } }
protected DataPopulationTestBase() { _fixture = new SafeFixture(); _mapper = new Mapper(new MapperConfiguration(expression => expression.AddProfile <ClashProfile>())); _random = new Random(); }