public async Task Then_The_Item_Is_Retrieved_By_Unique_Key( Shortlist item, List <Shortlist> recordsInDb, [Frozen] Mock <ICourseDeliveryReadonlyDataContext> mockContext, Data.Repository.ShortlistRepository repository) { //Arrange recordsInDb = recordsInDb.Select(c => { c.ShortlistUserId = item.ShortlistUserId; return(c); }).ToList(); recordsInDb[0].StandardId = item.StandardId; recordsInDb[0].Ukprn = item.Ukprn; recordsInDb[0].Lat = item.Lat; recordsInDb[0].Long = item.Long; mockContext .Setup(context => context.Shortlists) .ReturnsDbSet(recordsInDb); //Act var actual = await repository.GetShortlistUserItem(item); //Assert actual.Should() .BeEquivalentTo(recordsInDb.First(shortlist => shortlist.ShortlistUserId == item.ShortlistUserId && shortlist.Ukprn.Equals(item.Ukprn) && shortlist.StandardId.Equals(item.StandardId) && shortlist.Lat.Equals(item.Lat) && shortlist.Long.Equals(item.Long) )); }
public async Task Then_All_Records_Are_Deleted_Matching_User_Id( Guid firstUserId, List <Shortlist> firstUser, [Frozen] Mock <ICourseDeliveryDataContext> mockContext, Data.Repository.ShortlistRepository repository) { //Arrange firstUser = firstUser.Select(c => { c.ShortlistUserId = firstUserId; return(c); }).ToList(); mockContext .Setup(context => context.Shortlists) .ReturnsDbSet(firstUser); //Act await repository.DeleteShortlistByUserId(firstUserId); //Assert mockContext.Verify(x => x.Shortlists .Remove(It.Is <Shortlist>(c => c.ShortlistUserId.Equals(firstUserId))), Times.Exactly(firstUser.Count)); mockContext.Verify(x => x.SaveChanges(), Times.Once); }
public void Arrange() { _shortlistItem = new Shortlist { Id = Guid.NewGuid(), ShortlistUserId = Guid.NewGuid() }; _courseDeliveryDataContext = new Mock <ICourseDeliveryDataContext>(); _courseDeliveryDataContext.Setup(x => x.Shortlists).ReturnsDbSet(new List <Shortlist>()); _providerImportRepository = new Data.Repository.ShortlistRepository(Mock.Of <ILogger <Data.Repository.ShortlistRepository> >(), _courseDeliveryDataContext.Object, Mock.Of <ICourseDeliveryReadonlyDataContext>()); }
public async Task Then_The_Expired_ShortlistUserIds_Are_Returned( uint expiryPeriod, Guid firstUserId, Guid secondUserId, Guid thirdUserId, List <Shortlist> firstUser, List <Shortlist> secondUser, List <Shortlist> thirdUser, [Frozen] Mock <ICourseDeliveryReadonlyDataContext> mockContext, Data.Repository.ShortlistRepository repository) { //Arrange firstUser = firstUser.Select(c => { c.ShortlistUserId = firstUserId; c.CreatedDate = DateTime.UtcNow; return(c); }).ToList(); secondUser = secondUser.Select(c => { c.ShortlistUserId = secondUserId; c.CreatedDate = DateTime.UtcNow.AddDays(-expiryPeriod); return(c); }).ToList(); secondUser[0].CreatedDate = DateTime.UtcNow.AddDays(1); thirdUser = thirdUser.Select(c => { c.ShortlistUserId = thirdUserId; c.CreatedDate = DateTime.UtcNow.AddDays(-expiryPeriod); return(c); }).ToList(); var records = new List <Shortlist>(); records.AddRange(firstUser); records.AddRange(secondUser); records.AddRange(thirdUser); mockContext .Setup(context => context.Shortlists) .ReturnsDbSet(records); //Act var actual = (await repository.GetExpiredShortlistUserIds(expiryPeriod - 1)).ToList(); //Assert actual.Count.Should().Be(1); actual.First().Should().Be(thirdUserId); }
public async Task Then_Gets_From_DbContext( Guid userId, List <Shortlist> recordsInDb, [Frozen] Mock <ICourseDeliveryReadonlyDataContext> mockContext, Data.Repository.ShortlistRepository repository) { recordsInDb[0].ShortlistUserId = userId; mockContext .Setup(context => context.Shortlists) .ReturnsDbSet(recordsInDb); var actual = await repository.GetAllForUser(userId); actual.Should() .BeEquivalentTo(recordsInDb.Where(shortlist => shortlist.ShortlistUserId == userId)); }
public async Task Then_Gets_Number_Of_Items_For_That_User_From_DbContext_With_Standard( Guid userId, List <Shortlist> recordsInDb, [Frozen] Mock <ICourseDeliveryReadonlyDataContext> mockContext, Data.Repository.ShortlistRepository repository) { recordsInDb[0].ShortlistUserId = userId; recordsInDb[1].ShortlistUserId = userId; recordsInDb[1].ProviderStandard = null; mockContext .Setup(context => context.Shortlists) .ReturnsDbSet(recordsInDb); var actual = await repository.GetShortlistItemCountForUser(userId); actual.Should() .Be(recordsInDb.Count(shortlist => shortlist.ShortlistUserId == userId && shortlist.ProviderStandard != null)); }
public async Task And_If_No_Expired_Returns_Empty_List( uint expiryPeriod, Guid firstUserId, List <Shortlist> firstUser, [Frozen] Mock <ICourseDeliveryReadonlyDataContext> mockContext, Data.Repository.ShortlistRepository repository) { //Arrange firstUser = firstUser.Select(c => { c.ShortlistUserId = firstUserId; c.CreatedDate = DateTime.UtcNow; return(c); }).ToList(); mockContext .Setup(context => context.Shortlists) .ReturnsDbSet(firstUser); //Act var actual = (await repository.GetExpiredShortlistUserIds(expiryPeriod)).ToList(); //Assert actual.Any().Should().BeFalse(); }