public async Task UpdateFacility_State_Succeeds() { const string newState = "Alabama"; var facilityId = RepositoryData.Facilities()[0].Id; using var repositoryHelper = CreateRepositoryHelper(); using var repository = repositoryHelper.GetFacilityRepository(); var facility = ResourceHelper.GetFacilityDetail(facilityId); var updates = new FacilityEditDto(facility) { State = newState }; await repository.UpdateFacilityAsync(facilityId, updates); repositoryHelper.ClearChangeTracker(); var expected = ResourceHelper.GetFacilityDetail(facilityId); expected.State = newState; var updatedFacility = await repository.GetFacilityAsync(facilityId); updatedFacility.Should().BeEquivalentTo(expected); }
public async Task FacilityExists_Exists_ReturnsTrue() { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var result = await repository.FacilityExistsAsync(RepositoryData.Facilities()[0].Id); result.ShouldBeTrue(); }
public async Task CreateRecord_Succeeds() { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var record = new RetentionRecord() { Active = true, BoxNumber = "NewBox", ConsignmentNumber = "CN", EndYear = 2020, FacilityId = RepositoryData.Facilities()[0].Id, RetentionSchedule = "RS", ShelfNumber = "SN", StartYear = 2000, }; var newRecord = new RetentionRecordCreateDto() { BoxNumber = record.BoxNumber, ConsignmentNumber = record.ConsignmentNumber, EndYear = record.EndYear, RetentionSchedule = record.RetentionSchedule, ShelfNumber = record.ShelfNumber, StartYear = record.StartYear }; record.Id = await repository.CreateRetentionRecordAsync(record.FacilityId, newRecord); var result = await repository.GetRetentionRecordAsync(record.Id); result.Should().BeEquivalentTo(new RetentionRecordDetailDto(record)); }
public async Task FacilityNumberExists_DuplicateIsIgnored_ReturnsFalse() { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var ignoreId = RepositoryData.Facilities()[0].Id; var facName = RepositoryData.Facilities()[0].Name; var result = await repository.FacilityNumberExists(facName, ignoreId); result.ShouldBeFalse(); }
public async Task GetFacility_ReturnsCorrectFacility() { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var facility = RepositoryData.Facilities()[0]; var result = await repository.GetFacilityAsync(facility.Id); result.Id.Should().Be(facility.Id); result.Name.Should().Be(facility.Name); }
public async Task GetFacilityDetailListAsync_DefaultSpec_ReturnsActiveFacilities() { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var result = await repository.GetFacilityDetailListAsync(new FacilitySpec()); var expectedCount = RepositoryData.Facilities().Count(e => e.Active); result.Count.ShouldEqual(expectedCount); }
public async Task FacilityCount_DefaultSpec_ReturnsCountOfActiveFacilities() { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var spec = new FacilitySpec(); var result = await repository.CountAsync(spec); var expected = RepositoryData.Facilities().Count(e => e.Active); result.Should().Be(expected); }
public async Task FacilitySearch_DefaultSpec_ReturnsActiveFacilities() { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var result = await repository.GetFacilityPaginatedListAsync(new FacilitySpec(), 1, 999); var expectedCount = RepositoryData.Facilities().Count(e => e.Active); result.TotalCount.ShouldEqual(expectedCount); result.Items.Count.ShouldEqual(expectedCount); result.PageNumber.ShouldEqual(1); result.TotalPages.ShouldEqual(1); }
public async Task UndeleteFacility_Succeeds() { var facility = RepositoryData.Facilities().First(e => e.Active); using var repositoryHelper = CreateRepositoryHelper(); using var repository = repositoryHelper.GetFacilityRepository(); await repository.UndeleteFacilityAsync(facility.Id); repositoryHelper.ClearChangeTracker(); var updatedFacility = await repository.GetFacilityAsync(facility.Id); updatedFacility.Active.ShouldBeTrue(); }
public async Task FacilityCount_WithDeleted_ReturnsCountOfAll() { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var spec = new FacilitySpec() { ShowDeleted = true }; var result = await repository.CountAsync(spec); var expected = RepositoryData.Facilities().Count; result.Should().Be(expected); }
// [InlineData("ghi")] Sqlite is case-sensitive by default public async Task FacilityCount_ByFacilityNumber_ReturnsCorrectCount(string facilityNumberSpec) { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var spec = new FacilitySpec() { FacilityNumber = facilityNumberSpec }; var result = await repository.CountAsync(spec); var expected = RepositoryData.Facilities() .Count(e => e.FacilityNumber.ToLower().Contains(facilityNumberSpec.ToLower()) && e.Active); result.Should().Be(expected); }
public async Task FacilitySearch_BeyondLastPage_ReturnsEmptyList() { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var spec = new FacilitySpec() { ShowDeleted = true }; var result = await repository.GetFacilityPaginatedListAsync(spec, 999, 999); result.TotalCount.ShouldEqual(RepositoryData.Facilities().Count); result.Items.Count.ShouldEqual(0); result.PageNumber.ShouldEqual(999); result.TotalPages.ShouldEqual(1); }
public async Task FacilityCount_ByCounty_ReturnsCorrectCount() { const int countyId = 131; var spec = new FacilitySpec() { CountyId = countyId }; using var repository = CreateRepositoryHelper().GetFacilityRepository(); var result = await repository.CountAsync(spec); var expected = RepositoryData.Facilities() .Count(e => e.CountyId == countyId && e.Active); result.Should().Be(expected); }
public async Task FacilitySearch_Page2_ReturnsSecondPage() { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var spec = new FacilitySpec() { ShowDeleted = true }; var result = await repository.GetFacilityPaginatedListAsync(spec, 2, 2); var expectedPages = (int)Math.Ceiling(RepositoryData.Facilities().Count / 2m); result.TotalCount.ShouldEqual(RepositoryData.Facilities().Count); result.Items.Count.ShouldEqual(2); result.PageNumber.ShouldEqual(2); result.TotalPages.ShouldEqual(expectedPages); }
public async Task FacilitySearch_ByLocation_ReturnsCorrectList(string locationSpec) { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var spec = new FacilitySpec() { Location = locationSpec, ShowDeleted = true }; var result = await repository.GetFacilityPaginatedListAsync(spec, 1, 999); var expectedCount = RepositoryData.Facilities().Count(e => e.Location.Contains(locationSpec)); result.TotalCount.ShouldEqual(expectedCount); result.Items.Count.ShouldEqual(expectedCount); result.PageNumber.ShouldEqual(1); result.TotalPages.ShouldEqual(1); }
public async Task FacilitySearch_WithDeleted_ReturnsAllFacilities() { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var spec = new FacilitySpec() { ShowDeleted = true }; var result = await repository.GetFacilityPaginatedListAsync(spec, 1, 999); var expectedCount = RepositoryData.Facilities().Count; result.TotalCount.ShouldEqual(expectedCount); result.Items.Count.ShouldEqual(expectedCount); result.PageNumber.ShouldEqual(1); result.TotalPages.ShouldEqual(1); }
public async Task CreateFacility_WithExistingNumber_ThrowsException() { var existingNumber = RepositoryData.Facilities()[0].FacilityNumber; var facilityCreate = new FacilityCreateDto() { FacilityNumber = existingNumber, CountyId = 123 }; Func <Task> action = async() => { using var repository = CreateRepositoryHelper().GetFacilityRepository(); await repository.CreateFacilityAsync(facilityCreate); }; (await action.Should().ThrowAsync <ArgumentException>().ConfigureAwait(false)) .WithMessage($"Facility Number '{facilityCreate.FacilityNumber}' already exists."); }
public async Task OnGet_PopulatesThePageModel() { var facilityId = RepositoryData.Facilities()[0].Id; var facility = ResourceHelper.GetFacilityDetail(facilityId); var mockRepo = new Mock <IFacilityRepository>(); mockRepo.Setup(l => l.GetFacilityAsync(It.IsAny <Guid>())) .ReturnsAsync(facility) .Verifiable(); var pageModel = new UndeleteModel(mockRepo.Object); var result = await pageModel.OnGetAsync(facility.Id).ConfigureAwait(false); result.Should().BeOfType <PageResult>(); pageModel.Id.Should().Be(facility.Id); pageModel.FacilityDetail.Should().BeEquivalentTo(facility); }
// [InlineData("ghi")] Sqlite is case-sensitive by default public async Task FacilitySearch_ByFacilityNumber_ReturnsCorrectList(string facilityNumberSpec) { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var spec = new FacilitySpec() { FacilityNumber = facilityNumberSpec, ShowDeleted = true }; var result = await repository.GetFacilityPaginatedListAsync(spec, 1, 999); var expectedCount = RepositoryData.Facilities() .Count(e => e.FacilityNumber.ToLower().Contains(facilityNumberSpec.ToLower()) && e.Active); result.TotalCount.ShouldEqual(expectedCount); result.Items.Count.ShouldEqual(expectedCount); result.PageNumber.ShouldEqual(1); result.TotalPages.ShouldEqual(1); }
public async Task FacilitySearch_ByMissingCounty_ReturnsNone() { const int countySpec = 243; var spec = new FacilitySpec() { CountyId = countySpec, ShowDeleted = true }; using var repository = CreateRepositoryHelper().GetFacilityRepository(); var result = await repository.GetFacilityPaginatedListAsync(spec, 1, 999); var expectedCount = RepositoryData.Facilities().Count(e => e.CountyId == countySpec); result.TotalCount.ShouldEqual(expectedCount); result.Items.Count.ShouldEqual(expectedCount); result.PageNumber.ShouldEqual(1); result.TotalPages.ShouldEqual(0); }
public async Task UpdateFacility_WithNonexistentFile_ThrowsException() { const string newFileLabel = "999-9999"; Func <Task> action = async() => { using var repository = CreateRepositoryHelper().GetFacilityRepository(); var facilityId = RepositoryData.Facilities()[0].Id; var facility = ResourceHelper.GetFacilityDetail(facilityId); var updates = new FacilityEditDto(facility) { FileLabel = newFileLabel }; await repository.UpdateFacilityAsync(facilityId, updates); }; (await action.Should().ThrowAsync <ArgumentException>().ConfigureAwait(false)) .WithMessage($"File Label {newFileLabel} does not exist."); }
public async Task UpdateFacility_Longitude_Succeeds() { const decimal newLongitude = 1.0m; var facilityId = RepositoryData.Facilities()[0].Id; using var repositoryHelper = CreateRepositoryHelper(); using var repository = repositoryHelper.GetFacilityRepository(); var facility = ResourceHelper.GetFacilityDetail(facilityId); var updates = new FacilityEditDto(facility) { Longitude = newLongitude }; await repository.UpdateFacilityAsync(facilityId, updates); repositoryHelper.ClearChangeTracker(); var updatedFacility = await repository.GetFacilityAsync(facilityId); updatedFacility.Longitude.Should().Be(newLongitude); }
public async Task UpdateFacility_WithBlankFile_SucceedsAndCreatesNewFile() { var facilityId = RepositoryData.Facilities()[0].Id; using var repositoryHelper = CreateRepositoryHelper(); using var repository = repositoryHelper.GetFacilityRepository(); var facility = ResourceHelper.GetFacilityDetail(facilityId); var updates = new FacilityEditDto(facility) { FileLabel = "" }; await repository.UpdateFacilityAsync(facilityId, updates); repositoryHelper.ClearChangeTracker(); var updatedFacility = await repository.GetFacilityAsync(facilityId); updatedFacility.FileLabel.ShouldNotBeNull(); updatedFacility.FileLabel.Should().StartWith(RepositoryData.Facilities()[0].CountyId.ToString()); }
public async Task UpdateFacility_ChangeFile_Succeeds() { var facilityId = RepositoryData.Facilities()[0].Id; var newFile = RepositoryData.Files[1]; using var repositoryHelper = CreateRepositoryHelper(); using var repository = repositoryHelper.GetFacilityRepository(); var facility = ResourceHelper.GetFacilityDetail(facilityId); var updates = new FacilityEditDto(facility) { FileLabel = newFile.FileLabel }; await repository.UpdateFacilityAsync(facilityId, updates); repositoryHelper.ClearChangeTracker(); var updatedFacility = await repository.GetFacilityAsync(facilityId); updatedFacility.FileLabel.Should().Be(newFile.FileLabel); updatedFacility.FileId.Should().Be(newFile.Id); }
public async Task UpdateFacility_County_Succeeds() { const int newCountyId = 99; var facilityId = RepositoryData.Facilities()[0].Id; using var repositoryHelper = CreateRepositoryHelper(); using var repository = repositoryHelper.GetFacilityRepository(); var facility = ResourceHelper.GetFacilityDetail(facilityId); var updates = new FacilityEditDto(facility) { CountyId = newCountyId }; await repository.UpdateFacilityAsync(facilityId, updates); repositoryHelper.ClearChangeTracker(); var expected = ResourceHelper.GetFacilityDetail(facilityId); expected.County = ResourceHelper.GetCounty(newCountyId); var updatedFacility = await repository.GetFacilityAsync(facilityId); updatedFacility.Should().BeEquivalentTo(expected); }