Beispiel #1
0
        public void BreakExclusionsPost_Passes_WhenNull()
        {
            CreatePassModel model = GetCreatePassModel();

            _ = _fakeDataManipulator.Setup(m => m.Manipulate(It.IsAny <CreatePassModel>())).Returns(model);
            Assert.IsInstanceOf <OkNegotiatedContentResult <PassModel> >(_controller.Post(model));
        }
Beispiel #2
0
        public void PassSalesAreaPrioritySalesAreaPrioritiesDoesNotHaveDuplicates()
        {
            CreatePassModel model = this.GetCreatePassModel();

            model.PassSalesAreaPriorities.SalesAreaPriorities.Add(new SalesAreaPriorityModel()
            {
                SalesArea = "foo"
            });
            model.PassSalesAreaPriorities.SalesAreaPriorities.Add(new SalesAreaPriorityModel()
            {
                SalesArea = "foo"
            });
            model.PassSalesAreaPriorities.SalesAreaPriorities.Add(new SalesAreaPriorityModel()
            {
                SalesArea = "bar"
            });
            model.PassSalesAreaPriorities.SalesAreaPriorities.Add(new SalesAreaPriorityModel()
            {
                SalesArea = "bar"
            });
            model.PassSalesAreaPriorities.SalesAreaPriorities.Add(new SalesAreaPriorityModel()
            {
                SalesArea = "bar"
            });
            _ = _fakeDataManipulator.Setup(m => m.Manipulate(It.IsAny <CreatePassModel>())).Returns(model);
            Assert.That(() => this._controller.Post(model), Throws.Exception.TypeOf <Exception>().With.Property("Message").EqualTo("Duplicate SalesAreas: foo,bar"));
        }
Beispiel #3
0
        public void PassSalesAreaPriorityNullValueForSalesAreaPrioritiesValidation()
        {
            CreatePassModel model = this.GetCreatePassModel();

            model.PassSalesAreaPriorities.SalesAreaPriorities = null;
            _ = _fakeDataManipulator.Setup(m => m.Manipulate(It.IsAny <CreatePassModel>())).Returns(model);
            Assert.That(() => this._controller.Post(model), Throws.Exception.TypeOf <ArgumentNullException>().With.Property("Message").EqualTo("Value cannot be null.\r\nParameter name: PassSalesAreaPriority SalesAreaPriorities"));
        }
Beispiel #4
0
        public void PassSalesAreaPriorityInvalidDaysOfWeekValidation()
        {
            CreatePassModel model = this.GetCreatePassModel();

            model.PassSalesAreaPriorities.DaysOfWeek = "InvalidValue";
            _ = _fakeDataManipulator.Setup(m => m.Manipulate(It.IsAny <CreatePassModel>())).Returns(model);
            Assert.That(() => this._controller.Post(model), Throws.Exception.TypeOf <System.Text.RegularExpressions.RegexMatchTimeoutException>().With.Property("Message").EqualTo("Invalid PassSalesAreaPriority DaysOfWeek"));
        }
Beispiel #5
0
        public void ManipulateCreatePassModelWithNullValueDoesNotFail()
        {
            CreatePassModel model = null;

            model = _dataManipulator.Manipulate(model);

            Assert.That(model, Is.Null);
        }
Beispiel #6
0
 public CreatePassModel Manipulate(CreatePassModel command)
 {
     if (command != null && command.PassSalesAreaPriorities != null)
     {
         command.PassSalesAreaPriorities.StartDate = null;
         command.PassSalesAreaPriorities.EndDate   = null;
     }
     return(command);
 }
Beispiel #7
0
        public IHttpActionResult Post([FromBody] CreatePassModel command)
        {
            // Check empty name
            if (string.IsNullOrWhiteSpace(command.Name))
            {
                return(this.Error().InvalidParameters("Pass name must be set"));
            }

            if (!ModelState.IsValid)
            {
                return(this.Error().InvalidParameters("Invalid pass parameters"));
            }

            // Check that pass doesn't exist
            Pass pass = _passRepository.Get(command.Id);

            if (pass != null)
            {
                return(this.Error().InvalidParameters("Pass already exists"));
            }

            // Check that pass with such name doesn't exist
            pass = _passRepository.FindByName(command.Name, command.IsLibraried);
            if (pass != null)
            {
                return(this.Error().InvalidParameters("Pass with such name already exists"));
            }

            if (_passInspectorService.InspectPassSalesAreaPriorities(
                    command.PassSalesAreaPriorities,
                    out string errorMessage))
            {
                return(this.Error().InvalidParameters(errorMessage));
            }

            List <string> breakExclusionsErrorMessages = new List <string>();

            if (!BreakExclusionsValidations.DateTimeRangeIsValid(command.BreakExclusions, _salesAreaRepository.GetAll(), out breakExclusionsErrorMessages))
            {
                return(this.Error().InvalidParameters(breakExclusionsErrorMessages));
            }

            pass = _mapper.Map <Pass>(command);
            IdUpdater.SetIds(pass, _identityGeneratorResolver);

            // Validate
            ValidateForSave(pass);

            // Save
            _passRepository.Add(pass);
            _passRepository.SaveChanges();   // Do not remove this, need to persist changes now so that we can return PassModel

            return(Ok(Mappings.MapToPassModel(pass, _passRepository, _mapper)));
        }
Beispiel #8
0
        public void PassSalesAreaPrioritySalesAreaPrioritiesIsASubSetOfAllSalesAreasValidation()
        {
            CreatePassModel model = this.GetCreatePassModel();

            model.PassSalesAreaPriorities.SalesAreaPriorities[0] = new SalesAreaPriorityModel()
            {
                SalesArea = "foo"
            };
            _ = _fakeDataManipulator.Setup(m => m.Manipulate(It.IsAny <CreatePassModel>())).Returns(model);
            Assert.That(() => this._controller.Post(model), Throws.Exception.TypeOf <Exception>().With.Property("Message").EqualTo("foo is not a valid SalesArea"));
        }
Beispiel #9
0
        public void ManipulateCreatePassModelPassSalesAreaPrioritiesWithNullValueDoesNotFail()
        {
            var model = new CreatePassModel
            {
                PassSalesAreaPriorities = null
            };

            model = _dataManipulator.Manipulate(model);

            Assert.That(model.PassSalesAreaPriorities, Is.Null);
        }
Beispiel #10
0
        public void BreakExclusionsPost_Passes_WithCorrectDateTime()
        {
            CreatePassModel model = GetCreatePassModel();

            model.BreakExclusions.Add(new BreakExclusionModel()
            {
                EndDate   = DateTime.UtcNow,
                EndTime   = new TimeSpan(8, 0, 0),
                StartDate = DateTime.UtcNow,
                StartTime = new TimeSpan(6, 0, 0)
            });
            _ = _fakeDataManipulator.Setup(m => m.Manipulate(It.IsAny <CreatePassModel>())).Returns(model);
            Assert.IsInstanceOf <OkNegotiatedContentResult <PassModel> >(_controller.Post(model));
        }
Beispiel #11
0
        public void BreakExclusionsPost_Fails_NoTimesProvided()
        {
            CreatePassModel model = GetCreatePassModel();

            model.BreakExclusions.Add(new BreakExclusionModel()
            {
                EndDate   = DateTime.UtcNow.AddDays(1),
                EndTime   = null,
                StartDate = DateTime.UtcNow,
                StartTime = null
            });
            _ = _fakeDataManipulator.Setup(m => m.Manipulate(It.IsAny <CreatePassModel>())).Returns(model);
            Assert.IsInstanceOf <OkNegotiatedContentResult <PassModel> >(_controller.Post(model));
        }
Beispiel #12
0
        public void ManipulatePassSalesAreaPrioritiesWithEndDateValueSetsTheEndtDateToNull()
        {
            var model = new CreatePassModel
            {
                PassSalesAreaPriorities = new PassSalesAreaPriorityModel()
                {
                    EndDate = DateTime.Now
                }
            };

            model = _dataManipulator.Manipulate(model);

            Assert.That(model.PassSalesAreaPriorities.EndDate, Is.Null);
        }
Beispiel #13
0
        public void BreakExclusionsPost_Fails_ForOverlappingTimes()
        {
            CreatePassModel model = GetCreatePassModel();

            model.BreakExclusions.Add(new BreakExclusionModel()
            {
                SalesArea = "sa1",
                EndDate   = DateTime.UtcNow,
                EndTime   = new TimeSpan(6, 0, 0),
                StartDate = DateTime.UtcNow,
                StartTime = new TimeSpan(8, 0, 0)
            });
            _ = _fakeDataManipulator.Setup(m => m.Manipulate(It.IsAny <CreatePassModel>())).Returns(model);
            Assert.That(() => _controller.Post(model), Throws.Exception.TypeOf <ArgumentNullException>());
        }
Beispiel #14
0
        private CreatePassModel GetCreatePassModel()
        {
            CreatePassModel model = new CreatePassModel();

            model.Id      = 1;
            model.Name    = "Name";
            model.General = new List <GeneralModel>()
            {
                new GeneralModel()
                {
                    RuleId = (int)RuleID.MinimumEfficiency, Value = "1"
                }
            };
            model.Weightings = new List <WeightingModel>()
            {
                new WeightingModel()
            };
            model.Tolerances = new List <ToleranceModel>()
            {
                new ToleranceModel()
            };
            model.Rules = new List <PassRuleModel>()
            {
                new PassRuleModel()
            };
            model.PassSalesAreaPriorities           = new PassSalesAreaPriorityModel();
            model.PassSalesAreaPriorities.StartTime = new TimeSpan(1, 1, 1);
            model.PassSalesAreaPriorities.EndTime   = new TimeSpan(2, 2, 2);
            // NOTE: the below StartDate and EndDate are added since the tests were failing
            // The tests were failing since validations were added for StartDate and EndDate
            // but the test was not updated by the team member who did the change
            model.PassSalesAreaPriorities.StartDate           = DateTime.Now;
            model.PassSalesAreaPriorities.EndDate             = DateTime.Now.AddDays(6);
            model.PassSalesAreaPriorities.DaysOfWeek          = "1111111";
            model.PassSalesAreaPriorities.SalesAreaPriorities = new List <SalesAreaPriorityModel>()
            {
                new SalesAreaPriorityModel()
                {
                    SalesArea = "sa1"
                }
            };
            return(model);
        }