public void Query_WithGenericParameter_ReturnsGenericallyTypedIQueryable() { // Arrange sut = new KeylessRepository(_db); // Act var result = sut.Query <SuperTrillig>(); // Assert Assert.IsAssignableFrom <IQueryable <SuperTrillig> >(result); }
public void RawQuery_ReturnsNonTyped_IQueryable() { // Arrange _db.Database.EnsureDeleted(); _db.Database.EnsureCreated(); sut = new KeylessRepository(_db); var result = sut.RawQuery(); Assert.IsAssignableFrom <IQueryable>(result); }
public void QueryWithPredicate_WithNullExpress_ReturnsTypedIQueryable() { // Arrange sut = new KeylessRepository(_db); // Act var result = sut.Query(); // Assert Assert.IsAssignableFrom <IQueryable <Trillig> >(result); }
public async Task GetAsync_WithApplicableQueryReturns_AValue(string broName) { // Arrange sut = new KeylessRepository(_db); // Act var result = await sut.GetAsync(x => x.BrotherName == broName); // Assert Assert.NotNull(result); }
public async Task Exists_WithPredicate_ReturnsFalse_IfNotExists(string name) { // Arrange sut = new KeylessRepository(_db); // Act bool result = await sut.Exists(x => x.Name == name); // Assert Assert.False(result); }
public async Task GetAllAsync_WithPredicate_ReturnsMatchingValues(int id1, int id2, int id3) { // Arrange sut = new KeylessRepository(_db); // Act var result = await sut.GetAllAsync(x => new[] { id1, id2, id3 }.Contains(x.Id)); // Assert Assert.NotEmpty(result); Assert.Equal(3, result.Count()); }
public async Task GetAllAsync_ReturnsAllExistingValues() { // Arrange sut = new KeylessRepository(_db); // Act var result = await sut.GetAllAsync(); // Assert Assert.NotEmpty(result); Assert.Equal(5, result.Count()); }
public async Task UpdateAsync_SimplyCalls_DbSaveChangesAsync() { // Arrange var mockDb = new Mock <TestDbContext>(); var mockSet = new Mock <DbSet <Trillig> >(); mockDb.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).ReturnsAsync(1); mockDb.Setup(x => x.Set <Trillig>()).Returns(mockSet.Object); _db = mockDb.Object; sut = new KeylessRepository(_db); // Act await sut.UpdateAsync(); mockDb.Verify(x => x.SaveChangesAsync(default), Times.Once());
public async Task AddAsync_DoesNothing_When_objects_areEmpty() { // Arrange sut = new KeylessRepository(_db); // Act await sut.AddAsync(new Trillig[] { }); // Assert bool result = _db.Trilligs.Any(x => x.Name == "Z"); Assert.False(result); }
public async Task AddAsync_PersistsValuesTo_DataStore() { // Arrange Trillig toAdd = new Trillig() { Name = "F", BrotherName = "No Brother" }; sut = new KeylessRepository(_db); // Act await sut.AddAsync(toAdd); // Assert bool result = _db.Trilligs.Any(x => x.Name == "F"); Assert.True(result); }
public async Task DeleteAsync_RemovesValues_FromStore(int id) { var mockDb = new Mock <TestDbContext>(); var mockSet = new Mock <DbSet <Trillig> >(); var trilligList = _db.Trilligs.ToList(); mockDb.Setup(x => x.Set <Trillig>()).Returns(mockSet.Object); mockSet.Setup(y => y.Remove(It.IsAny <Trillig>())).Callback <Trillig>((t) => trilligList.Remove(t)); mockSet.Setup(y => y.RemoveRange(It.IsAny <Trillig[]>())).Callback <Trillig>((t) => trilligList.RemoveAll(x => x.Id == t.Id)); _db = mockDb.Object; sut = new KeylessRepository(_db); await sut.DeleteAsync(new Trillig() { Id = id }); bool stillExists = trilligList.Any(x => x.Id == id); Assert.False(stillExists); }
public void WhenConstructingTheRepository_ItWill_BeCreated() { sut = new KeylessRepository(_db); Assert.NotNull(sut); }