public void Given_a_query_and_dates_are_BST_then_dates_return_as_UTC() { //given var BSTDate = new DateTime(2014, 04, 06); var clientId = 234234; var clientAccountNumber = "TESTACTULAR"; var expectedStatus = "Open"; var checklist = new Checklist(){VisitDate = BSTDate}; var site = new SiteAddressResponse() {Id = 1212431241, SiteName = "Rekall", Postcode = "MARS 7TU"}; _clientDetailsService .Setup(x => x.GetSite(clientId, (int)site.Id)) .Returns(() => site); _clientDetailsService .Setup(x => x.GetByClientAccountNumber(clientAccountNumber)) .Returns(() => new CompanyDetailsResponse() { CAN = clientAccountNumber, Id = clientId }); _clientDetailsService .Setup(x => x.Get(It.IsAny<int>())) .Returns(new CompanyDetails() { CAN = "Can" }); _getChecklistsQuery.Setup(x => x.WithClientId(It.IsAny<int>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery.Setup(x => x.WithConsultantName(It.IsAny<string>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery.Setup(x => x.WithStatus(It.IsAny<string>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery.Setup(x => x.WithStatusDateBetween(It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery.Setup(x => x.Execute()) .Returns(() => new List<ChecklistIndex>() { new ChecklistIndex() {ClientId = clientId, SiteId = (int?) site.Id, Status = expectedStatus, VisitDate = BSTDate, CompletedDate = BSTDate, SubmittedDate = BSTDate, QaAdvisorAssignedOn = BSTDate} }); //when var target = new ChecklistController(_dependencyFactory.Object); var result = target.Query(clientAccountNumber, null, null, null, false, false, null, null); Assert.That(result.First().VisitDate, Is.EqualTo(BSTDate.ToUniversalTime())); Assert.That(result.First().CompletedOn, Is.EqualTo(BSTDate.ToUniversalTime())); Assert.That(result.First().SubmittedOn, Is.EqualTo(BSTDate.ToUniversalTime())); Assert.That(result.First().QaAdvisorAssignedOn, Is.EqualTo(BSTDate.ToUniversalTime())); }
public void given_parameters_when_query_then_execute_is_called_with_correct_parameters() { //given int clientId = 1234; string can = "CAN01"; string checklistCreatedBy ="consultant.name"; string visitDate = DateTime.Now.ToShortDateString(); string checklistStatus = "Draft"; bool includeDeleted = false; bool excludeSubmitted = true; var checklist = new Checklist(); var site = new SiteAddressResponse() {Id = 1234L,}; _clientDetailsService .Setup(x => x.GetByClientAccountNumber(can)) .Returns(() => new CompanyDetailsResponse() {CAN = can, Id = clientId}); _clientDetailsService .Setup(x => x.Get(It.IsAny<int>())) .Returns(new CompanyDetails() {CAN = "Can"}); _clientDetailsService .Setup(x => x.GetSite(It.IsAny<int>(), It.IsAny<int>())) .Returns(() => site); _getChecklistsQuery.Setup(x => x.WithClientId(It.IsAny<int>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery.Setup(x => x.WithStatus(It.IsAny<string>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery.Setup(x => x.WithStatusDateBetween(It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery.Setup(x => x.WithConsultantName(It.IsAny<string>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery .Setup( x => x.Execute()) .Returns(() => new List<ChecklistIndex>() { new ChecklistIndex() {ClientId = clientId, SiteId = (int?) site.Id, Status = checklistStatus} }); _checklistRepository.Setup(x => x.GetById(It.IsAny<Guid>())) .Returns(checklist); //when var target = new ChecklistController(_dependencyFactory.Object); target.Query(can, checklistCreatedBy, visitDate, checklistStatus, includeDeleted, excludeSubmitted, null, null); //then _getChecklistsQuery .Verify( x => x.Execute()); }
public void Given_i_query_by_client_account_number_then_the_site_details_are_set() { //given var clientId = 234234; var clientAccountNumber = "TESTACTULAR"; var expectedPostcode = "MARS 7TU"; var expectedSiteName = "Rekall"; var expectedAddress = "29 Acaciar Road"; var expectedStatus = "Open"; var checklist = new Checklist(); var site = new SiteAddressResponse() {Id = 1212431241, SiteName = expectedSiteName, Postcode = expectedPostcode, Address1 = expectedAddress}; _clientDetailsService .Setup(x => x.GetSite(clientId, (int) site.Id)) .Returns(() => site); _clientDetailsService .Setup(x => x.GetByClientAccountNumber(clientAccountNumber)) .Returns(() => new CompanyDetailsResponse() {CAN = clientAccountNumber, Id = clientId}); _clientDetailsService .Setup(x => x.Get(It.IsAny<int>())) .Returns(new CompanyDetails() { CAN = "Can" }); _checklistRepository.Setup(x => x.Search(clientId, null, null, null, false, null)) .Returns(() => new List<Checklist>() { new Checklist() {ClientId = clientId, SiteId = (int?) site.Id, Status = expectedStatus} }); _checklistRepository.Setup(x => x.GetById(It.IsAny<Guid>())) .Returns(checklist); _getChecklistsQuery.Setup(x => x.WithClientId(It.IsAny<int>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery.Setup(x => x.WithConsultantName(It.IsAny<string>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery.Setup(x => x.WithStatus(It.IsAny<string>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery.Setup(x => x.WithStatusDateBetween(It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery.Setup(x=> x.Execute()) .Returns(() => new List<ChecklistIndex>() { new ChecklistIndex() {ClientId = clientId, SiteId = (int?) site.Id, Status = expectedStatus} }); //when var target = new ChecklistController(_dependencyFactory.Object); var result = target.Query(clientAccountNumber, null, null, null, false, false, null,null); Assert.That(result.First().Site.Postcode, Is.EqualTo(expectedPostcode)); Assert.That(result.First().Site.SiteName, Is.EqualTo(expectedSiteName)); Assert.That(result.First().Site.Address1, Is.EqualTo(expectedAddress)); Assert.That(result.First().Status, Is.EqualTo(expectedStatus)); }
public void Given_i_query_by_user_then_the_createBy_and_qaAdvisor_are_queried() { var clientId = 234234; var clientAccountNumber = "TESTACTULAR"; var expectedPostcode = "MARS 7TU"; var expectedSiteName = "Rekall"; var expectedAddress = "29 Acaciar Road"; var userName = "******"; var qaAdvisorId = Guid.NewGuid(); var site = new SiteAddressResponse() { Id = 1212431241, SiteName = expectedSiteName, Postcode = expectedPostcode, Address1 = expectedAddress }; _clientDetailsService .Setup(x => x.GetSite(clientId, (int)site.Id)) .Returns(() => site); _clientDetailsService .Setup(x => x.GetByClientAccountNumber(clientAccountNumber)) .Returns(() => new CompanyDetailsResponse() { CAN = clientAccountNumber, Id = clientId }); _clientDetailsService .Setup(x => x.Get(It.IsAny<int>())) .Returns(new CompanyDetails() { CAN = "Can" }); _qaAdvisorRepository .Setup(x => x.GetByFullname(userName)) .Returns(() => new QaAdvisor() {Id = qaAdvisorId, Forename = "Jack", Surname = "Reacher"}); _getChecklistsQuery.Setup(x => x.WithConsultantName(It.IsAny<string>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery.Setup(x => x.WithClientId(It.IsAny<int>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery.Setup(x => x.WithStatus(It.IsAny<string>())).Returns(_getChecklistsQuery.Object); _getChecklistsQuery.Setup(x => x.WithStatusDateBetween(It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(_getChecklistsQuery.Object); //when var target = new ChecklistController(_dependencyFactory.Object); var result = target.Query(null, userName, null, null, false, false, null, null); _getChecklistsQuery .Verify(x => x.Execute(),Times.Once); }
public void Given_i_query_by_visit_date_then_the_site_details_are_set() { var clientId = 234234; var clientAccountNumber = "TESTACTULAR"; var expectedPostcode = "MARS 7TU"; var expectedSiteName = "Rekall"; var expectedAddress = "29 Acaciar Road"; var expectedStatus = "Open"; var visitDate = DateTime.Now; var site = new SiteAddressResponse() { Id = 1212431241, SiteName = expectedSiteName, Postcode = expectedPostcode, Address1 = expectedAddress }; _clientDetailsService .Setup(x => x.GetSite(clientId, (int)site.Id)) .Returns(() => site); _clientDetailsService .Setup(x => x.GetByClientAccountNumber(clientAccountNumber)) .Returns(() => new CompanyDetailsResponse() { CAN = clientAccountNumber, Id = clientId }); _clientDetailsService .Setup(x => x.Get(It.IsAny<int>())) .Returns(new CompanyDetails() { CAN = "Can" }); _checklistRepository.Setup(x => x.Search(null, null, visitDate.ToShortDateString(), null, false, null)) .Returns(() => new List<Checklist>() { new Checklist() {ClientId = clientId, SiteId = (int?) site.Id, VisitDate = visitDate, Status = expectedStatus} }); //when var target = new ChecklistController(_dependencyFactory.Object); var result = target.Query(null, null, visitDate.ToShortDateString(), null, false); //Assert.That(result.All(x => string.IsNullOrEmpty(x.Postcode) == false), Is.EqualTo(false)); Assert.That(result.First().Site.Postcode, Is.EqualTo(expectedPostcode)); Assert.That(result.First().Site.SiteName, Is.EqualTo(expectedSiteName)); Assert.That(result.First().VisitDate, Is.EqualTo(visitDate)); Assert.That(result.First().Site.Address1, Is.EqualTo(expectedAddress)); Assert.That(result.First().Status, Is.EqualTo(expectedStatus)); }