public void RequirementMapper_DoesNotMap_RequirementReference()
        {
            //Arrange
            const string reference = "ABCD1234";
            var requirement1 = new Requirement { RequirementReference = reference };
            var requirement2 = new Requirement { RequirementReference = string.Empty };

            //Act
            _mapper.Map(requirement2, requirement1);

            //Assert
            requirement1.RequirementReference.Should().Be(reference);
        }
        public void RequirementMapper_DoesNotMap_RequirementId()
        {
            //Arrange
            const int id = 123;
            var requirement1 = new Requirement { RequirementId = id };
            var requirement2 = new Requirement { RequirementId = 0 };

            //Act
            _mapper.Map(requirement2, requirement1);

            //Assert
            requirement1.RequirementId.Should().Be(id);
        }
        public void RequirementMapper_DoesNotMap_DateDeleted()
        {
            //Arrange
            var dateDeleted = DateTime.UtcNow;
            var requirement1 = new Requirement { DateDeleted = dateDeleted };
            var requirement2 = new Requirement { DateDeleted = DateTime.MinValue };

            //Act
            _mapper.Map(requirement2, requirement1);

            //Assert
            requirement1.DateDeleted.Should().Be(dateDeleted);
        }
        public bool CreateRequirementForApplication(string applicationReference, Requirement requirement)
        {
            if (string.IsNullOrEmpty(applicationReference))
                return false;

            var application =
                _applicationsContext.Applications
                    .Active()
                    .NotArchived()
                    .Include(r => r.Requirements)
                    .FirstOrDefault(a => a.ApplicationReference == applicationReference);

            if (application == null)
                return false;

            application.Requirements.Add(requirement);
            application.MarkUpdated();

            return _applicationsContext.SaveChanges() > 0;
        }
        public bool UpdateRequirementForApplication(string applicationReference, string requirementReference,
            Requirement requirement)
        {
            var application =
                _applicationsContext.Applications
                    .Active()
                    .NotArchived()
                    .Include(r => r.Requirements)
                    .FirstOrDefault(a => a.ApplicationReference == applicationReference);

            var existingRequirement =
                application?.Requirements.Active().FirstOrDefault(r => r.RequirementReference == requirementReference);

            if (existingRequirement == null)
                return false;

            var isDirty = _requirementMapper.Map(requirement, existingRequirement);

            if(isDirty)
                application.MarkUpdated();

            return !isDirty || _applicationsContext.SaveChanges() > 0;
        }
        public void RequirementMapper_Maps_Value()
        {
            //Arrange
            const string value = "This is a test value";
            var requirement1 = new Requirement { Value = string.Empty };
            var requirement2 = new Requirement { Value = value };

            //Act
            _mapper.Map(requirement2, requirement1);

            //Assert
            requirement1.Value.Should().Be(value);
        }
        public void RequirementMapper_Maps_RequirementType()
        {
            //Arrange
            const RequirementType type = RequirementType.Furnished;
            var requirement1 = new Requirement { RequirementType = RequirementType.Parking };
            var requirement2 = new Requirement { RequirementType = type };

            //Act
            _mapper.Map(requirement2, requirement1);

            //Assert
            requirement1.RequirementType.Should().Be(type);
        }