public async Task GetAllAwardsShouldReturnZeroWhenAwardsAreDeleted() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); var awards = new List <Award>(); for (int i = 1; i <= 10; i++) { awards.Add( new Award { Name = $"test{i}", CreatedOn = DateTime.UtcNow, IsDeleted = true, DeletedOn = DateTime.UtcNow, }); } await db.Awards.AddRangeAsync(awards); await db.SaveChangesAsync(); var awardsService = new AwardsService(db); var result = await awardsService.GetAllAwardsAsync <AwardTestModel>(); Assert.Empty(result); }
public async Task DoesAwardExistMethodShouldReturnTrueIfExists() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); var awards = new List <Award> { new Award { Name = "test1", CreatedOn = DateTime.UtcNow, }, new Award { Name = "test2", CreatedOn = DateTime.UtcNow, }, new Award { Name = "test3", CreatedOn = DateTime.UtcNow, }, }; await db.Awards.AddRangeAsync(awards); await db.SaveChangesAsync(); var awardsService = new AwardsService(db); Assert.True(await awardsService.DoesAwardIdExistAsync(1)); }
public async Task DeleteEntityTest() { var fakeRepositoryMock = new Mock <IProfileInfoesContext>(); fakeRepositoryMock.Setup(x => x.GetProfileInfoesList()).ReturnsAsync(vars); var profileInfoesService = new AwardsService(fakeRepositoryMock.Object); await profileInfoesService.DeleteProfileInfo(2); }
public async Task DeleteEntityTest() { var fakeRepositoryMock = new Mock <IAwardsContext>(); fakeRepositoryMock.Setup(x => x.GetAwardsList()).ReturnsAsync(vars); var awardService = new AwardsService(fakeRepositoryMock.Object); await awardService.DeleteAward(2); }
public async Task GetSingleEntityTest() { var fakeRepositoryMock = new Mock <IAwardsContext>(); fakeRepositoryMock.Setup(x => x.GetAwardsSingle(It.IsAny <int>())).ReturnsAsync(var); var awardService = new AwardsService(fakeRepositoryMock.Object); var result = await awardService.GetAwardsSingle(3); Assert.Equal("Ham Ham", result.Name); }
public async Task GetAllAwardsShouldReturnZeroWhenAwardsAreEmpty() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); var awards = new List <Award>(); var awardsService = new AwardsService(db); var result = await awardsService.GetAllAwardsAsync <AwardTestModel>(); Assert.Empty(result); }
public async Task GetAwardsLimitOffsetTest() { var dbContext = _serviceProvider.GetRequiredService <BookContext>(); await CreateSampleTask(dbContext); var service = new AwardsService(dbContext); AwardRequest request = new AwardRequest { Sort = AwardSort.Id, Limit = 1, Offset = 1 }; var response = await service.GetAwardsAsync(request); Assert.NotNull(response); Assert.Equal(1, response.Values.Count); Assert.Equal(2, response.Values[0].AwardId); Assert.Equal("Hugo", response.Values[0].Name); }
public async Task GetAwardTest() { var dbContext = _serviceProvider.GetRequiredService <BookContext>(); await CreateSampleTask(dbContext); var service = new AwardsService(dbContext); var award = await service.GetAwardAsync(1); Assert.NotNull(award); Assert.Equal(1, award.AwardId); Assert.Equal("Nebula", award.Name); Assert.NotNull(award.FirstContestDate); //Assert.Equal(1992, award.FirstContestDate.Value.Year); Assert.NotNull(award.LastContestDate); //Assert.Equal(2015, award.LastContestDate.Value.Year); }
public async Task GetAwardsSortRusnameTest() { var dbContext = _serviceProvider.GetRequiredService <BookContext>(); await CreateSampleTask(dbContext); var service = new AwardsService(dbContext); AwardRequest request = new AwardRequest { Sort = AwardSort.Rusname }; var response = await service.GetAwardsAsync(request); Assert.NotNull(response); Assert.Equal(3, response.Values.Count); Assert.Equal("Nebula", response.Values[0].Name); Assert.Equal("Oscar", response.Values[1].Name); Assert.Equal("Hugo", response.Values[2].Name); }
public async Task GetEntityListTest() { var fakeRepositoryMock = new Mock <IAwardsContext>(); fakeRepositoryMock.Setup(x => x.GetAwardsList()).ReturnsAsync(vars); var profileInfoesService = new AwardsService(fakeRepositoryMock.Object); var result = await profileInfoesService.GetAwardsList(); Assert.Collection(result, var => { Assert.Equal("Seb Seb", var.Name); }, car => { Assert.Equal("Ham Ham", var.Name); }); }
public async Task GetAwardsTest() { var dbContext = _serviceProvider.GetRequiredService <BookContext>(); await CreateSampleTask(dbContext); var service = new AwardsService(dbContext); AwardRequest request = new AwardRequest { Sort = AwardSort.Id }; var response = await service.GetAwardsAsync(request); Assert.NotNull(response); Assert.Equal(3, response.Values.Count); Assert.Equal(1, response.Values[0].AwardId); Assert.Equal("Nebula", response.Values[0].Name); Assert.NotNull(response.Values[0].FirstContestDate); //Assert.Equal(1992, response[0].FirstContestDate.Value.Year); Assert.NotNull(response.Values[0].LastContestDate); //Assert.Equal(2015, response[0].LastContestDate.Value.Year); }
public AwardsController(AwardsService service) { _service = service; }
public async Task SetEntityTest() { var fakeRepository = Mock.Of <IAwardsContext>(); var awardService = new AwardsService(fakeRepository); await awardService.SetAward(var); }
/// <summary> /// Constructor /// </summary> /// <param name="awardsService"></param> public AwardsController(AwardsService <AwardsViewModel, Award> awardsService) { _awardsService = awardsService; }