public bool CreateCustomerCheckResultForApplication(string applicationReference, string customerReference, CheckResult checkResult) { if (string.IsNullOrEmpty(applicationReference) || string.IsNullOrEmpty(customerReference)) return false; var application = _applicationsContext.Applications .Active() .NotArchived() .Include(c => c.Customers.Select(w => w.WhiteBoxCheckResults)) .FirstOrDefault(a => a.ApplicationReference == applicationReference); var customer = application?.Customers.Active().FirstOrDefault(c => c.CustomerReference == customerReference); if (customer == null) return false; customer.WhiteBoxCheckResults.Add(checkResult); customer.MarkUpdated(); application.MarkUpdated(); return _applicationsContext.SaveChanges() > 0; }
public bool UpdateCustomerCheck(string applicationReference, string customerReference, string checkReference, CheckResult checkResult) { Check.If(applicationReference).IsNotNullOrEmpty(); Check.If(customerReference).IsNotNullOrEmpty(); Check.If(checkReference).IsNotNullOrEmpty(); Check.If(checkResult).IsNotNull(); return _checkRepository.UpdateCustomerCheckResultForApplication(applicationReference, customerReference, checkReference, checkResult); }
public void CheckResultMapper_DoesNotMap_DateDeleted() { //Arrange var dateDeleted = DateTime.UtcNow; var address1 = new CheckResult { DateDeleted = dateDeleted }; var address2 = new CheckResult { DateDeleted = DateTime.MinValue }; //Act _mapper.Map(address2, address1); //Assert address1.DateDeleted.Should().Be(dateDeleted); }
public void CheckResultMapper_DoesNotMap_DateCreated() { //Arrange var dateCreated = DateTime.UtcNow; var checkResult1 = new CheckResult { DateCreated = dateCreated }; var checkResult2 = new CheckResult { DateCreated = DateTime.MinValue }; //Act _mapper.Map(checkResult2, checkResult1); //Assert checkResult1.DateCreated.Should().Be(dateCreated); }
public void CheckResultMapper_DoesNotMap_CheckResultReference() { //Arrange const string reference = "ABCD1234"; var checkResult1 = new CheckResult { CheckResultReference = reference }; var checkResult2 = new CheckResult { CheckResultReference = string.Empty }; //Act _mapper.Map(checkResult2, checkResult1); //Assert checkResult1.CheckResultReference.Should().Be(reference); }
public void CheckResultMapper_DoesNotMap_CheckResultId() { //Arrange const int id = 123; var checkResult1 = new CheckResult { CheckResultId = id }; var checkResult2 = new CheckResult { CheckResultId = 0 }; //Act _mapper.Map(checkResult2, checkResult1); //Assert checkResult1.CheckResultId.Should().Be(id); }
public string CreateCustomerCheck(string applicationReference, string customerReference, CheckResult checkResult) { Check.If(applicationReference).IsNotNullOrEmpty(); Check.If(customerReference).IsNotNullOrEmpty(); Check.If(checkResult).IsNotNull(); if (!string.IsNullOrEmpty(checkResult.CheckResultReference)) { return null; } var result = _checkRepository.CreateCustomerCheckResultForApplication(applicationReference, customerReference, checkResult.CreateReference(_referenceGenerator)); return result ? checkResult.CheckResultReference : null; }
public bool UpdateCustomerCheckResultForApplication(string applicationReference, string customerReference, string checkReference, CheckResult checkResult) { var application = _applicationsContext.Applications .Active() .NotArchived() .Include(c => c.Customers.Select(w => w.WhiteBoxCheckResults)) .FirstOrDefault(a => a.ApplicationReference == applicationReference); var existingCustomer = application?.Customers.Active().FirstOrDefault(c => c.CustomerReference == customerReference); var existingCheckResult = existingCustomer?.WhiteBoxCheckResults.Active() .FirstOrDefault(w => w.CheckResultReference == checkReference); if (existingCheckResult == null) return false; var isDirty = _checkResultMapper.Map(checkResult, existingCheckResult); if (isDirty) { existingCustomer.MarkUpdated(); application.MarkUpdated(); } return !isDirty || _applicationsContext.SaveChanges() > 0; }
public void CheckResultMapper_Maps_DateOfCheck() { //Arrange var dateOfCheck = DateTime.UtcNow; var checkResult1 = new CheckResult { DateofCheck = DateTime.MinValue }; var checkResult2 = new CheckResult { DateofCheck = dateOfCheck }; //Act _mapper.Map(checkResult2, checkResult1); //Assert checkResult1.DateofCheck.Should().Be(dateOfCheck); }
public void CheckResultMapper_Maps_CheckResultUrl() { //Arrange const string url = "http://www.thisistherighturl.com"; var checkResult1 = new CheckResult { CheckResultUrl = "http://www.thisisthewrongurl.com" }; var checkResult2 = new CheckResult { CheckResultUrl = url }; //Act _mapper.Map(checkResult2, checkResult1); //Assert checkResult1.CheckResultUrl.Should().Be(url); }