public async Task AddOrUpdatePerson_CallsAddOrUpdateFromDbSet() { // Arrange var mockSet = NSubstituteUtils.CreateMockDbSet <Person>(); var mockContext = Substitute.For <IPeopleDbContext>(); mockContext.People.Returns(mockSet); var service = new PeopleService(mockContext); // Act await service.AddOrUpdatePerson(new Person { FirstName = "John", LastName = "Doe" }); // Assert // verify that DbSet.AddOrUpdate has been called once mockSet.Received(1).AddOrUpdate(Arg.Any <Person>()); await mockContext.Received(1).SaveChangesAsync(); }