/// <inheritdoc /> public async Task Process(FakeCrudAddCommand request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } using (var dbContext = new FakeDbContext(_fakeDbContextOptions)) { var entity = new FakeAddPreProcessAuditDbSet { Value = request.RequestDto, Created = DateTimeOffset.UtcNow }; _ = dbContext.FakeAddPreProcessAudit.Add(entity); var saveResult = await dbContext.SaveChangesAsync(cancellationToken) .ConfigureAwait(false); _saveResultLogMessage( _logger, saveResult, null); } }
static void Main(string[] args) { //Prepare data FakeDbContext _dbContext = new FakeDbContext(); var products = new Repository <Product>(_dbContext); var discounts = new Repository <Discount>(_dbContext); ICheckout checkout = new ShopCheckout(products, discounts); products.Add(new Product { SKU = "A99", Price = 0.50m }); products.Add(new Product { SKU = "B15", Price = 0.30m }); products.Add(new Product { SKU = "C40", Price = 0.60m }); discounts.Add(new Discount { SKU = "A99", Quantity = 3, Value = 1.30m }); discounts.Add(new Discount { SKU = "B15", Quantity = 2, Value = 0.45m }); //Test Checkout checkout.Scan("A99"); checkout.Scan("A99"); checkout.Scan("A99"); checkout.Scan("A99"); checkout.Scan("B15"); Console.WriteLine($"Total cost of shopping is {checkout.Total()}"); }
public async Task UnitOfWork_NoAnyProvider_DbContextManualDispose_Async() { //没有事务支持程序 var provider = GetServiceProvider(); var uowManager = provider.GetService <IUnitOfWorkManager>(); FakeDbContext fakeDbContext; ScopeDbExecutor fakeDbExecutor; using (var uow = uowManager.Create()) { using (var dbContext = new FakeDbContext()) { fakeDbContext = dbContext; fakeDbExecutor = new ScopeDbExecutor(dbContext); await uow.TryAddDbExecutorAsync(fakeDbExecutor); await uow.SaveChangesAsync(); Assert.False(fakeDbExecutor.HasTransaction); Assert.False(fakeDbContext.IsDispose); } //手动释放了dbcontext; Assert.True(fakeDbContext.IsDispose); } //dbContext还会在工作单元释放时被释放,但是不会报错。 Assert.True(fakeDbContext.IsDispose); }
public void Setup() { DbConnection inMemoryConnection = DbConnectionFactory.CreateTransient(); _dbContext = new FakeDbContext(inMemoryConnection); _repository = new FakeRepository(_dbContext); }
public void InsertSimpleEntityFollowedByAnUpdate() { // Arrange const string updatedValue = "Updated Value"; FakeDbContext dbContext = new FakeDbContext(); SimpleEntityRepository entityRepository = new SimpleEntityRepository(dbContext); SimpleEntity simpleEntity = new SimpleEntity { Id = 1, SomeProperty = "Initial value" }; // Act entityRepository.Insert(simpleEntity); simpleEntity.SomeProperty = updatedValue; entityRepository.Update(simpleEntity); // Assert Assert.IsNotNull(entityRepository.DbContext); Assert.AreEqual(1, entityRepository.DbContext.ChangeTracker.Entries().Count()); // Ensure the entity in cache is still at a state of 'Added' but has the updated properties DbEntityEntry entry = entityRepository.DbContext.ChangeTracker.Entries().ToList()[0]; Assert.AreEqual(EntityState.Added, entry.State); Assert.AreEqual(updatedValue, ((SimpleEntity)entry.Entity).SomeProperty); }
public void Using_TableNoTracking_Queryable_Cannot_Save_Changes() { var options = DatabaseOptionsWithData <FakeDbContext>(typeof(FakeDbContext)); var fakeEntities = new FakeEntities(); var fakeEntity = fakeEntities[0]; using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var entityToUpdate = repository.TableNoTracking.Single(prop => prop.EntityCode == fakeEntity.EntityCode); entityToUpdate.EntityName = "Modified"; var saveCount = repository.SaveChanges(); Assert.Equal(0, saveCount); } using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var result = repository.Select(); var singleResult = result.Single(prop => prop.EntityCode == fakeEntity.EntityCode); Assert.Equal(fakeEntities.Count, result.Count()); Assert.NotEqual("Modified", singleResult.EntityName); Assert.NotEqual(Principal.Identity.Name, singleResult.ModifiedBy); Assert.False(singleResult.ModifiedTime > singleResult.CreatedTime); } }
public void UpdateMultipleSimpleEntities() { // Arrange const int expectedId1 = 10; const int expectedId2 = 10; FakeDbContext dbContext = new FakeDbContext(); SimpleEntityRepository entityRepository = new SimpleEntityRepository(dbContext); SimpleEntity simpleEntity1 = new SimpleEntity { Id = expectedId1 }; SimpleEntity simpleEntity2 = new SimpleEntity { Id = expectedId2 }; // Act entityRepository.Update(simpleEntity1); entityRepository.Update(simpleEntity2); // Assert Assert.IsNotNull(entityRepository.DbContext); Assert.AreEqual(1, entityRepository.DbContext.ChangeTracker.Entries().Count()); Assert.AreEqual(EntityState.Modified, entityRepository.DbContext.FindEntity(simpleEntity1.Id).State); Assert.AreEqual(EntityState.Modified, entityRepository.DbContext.FindEntity(simpleEntity2.Id).State); }
public void Add() { // Arrange FakeDbContext db = new FakeDbContext(); db.AddSet(TestData.Contacts); int newContactId = TestData.Contacts.Select(c => c.ContactId) .DefaultIfEmpty(0).Max() + 1; var newContact = new Contact { ContactId = newContactId, FirstName = "Anita", Surname = "Bath", EmailAddress = "*****@*****.**" }; // Act db.Add(newContact); var addedContact = db.Find <Contact>(newContactId); // Assert Assert.AreEqual("Bath", addedContact.Surname, "New contact surname check failed!!"); Assert.AreEqual(1, db.Added.Count, "New contact count check failed!!"); }
public void IniciarCenario() { var connection = DbConnectionFactory.CreatePersistent(Guid.NewGuid().ToString()); _fakeDbContext = new FakeDbContext(connection); _repositorio = new NotaFiscalEmitidaRepositorioSql(); _notaFiscalRepositorioXML = new NotaFiscalRepositorioXML(); _destinatarioRepositorio = new DestinatarioRepositorioSql(_fakeDbContext); _emitenteRepositorio = new EmitenteRepositorioSql(_fakeDbContext); _transportadorRepositorio = new TransportadorRepositorioSql(_fakeDbContext); _produtoNotaFiscalRepositorioSql = new ProdutoNotaFiscalRepositorioSql(_fakeDbContext); long idEmitenteCadastradoPorBaseSql = 1; long idDestinatarioCadastradoPorBaseSql = 1; long idTransportadorCadastradoPorBaseSql = 1; long idProdutoNotaFiscalCadastradorPorBaseSql = 1; _notaFiscalValida = ObjectMother.PegarNotaFiscalValidaComIdDasDependencias(idEmitenteCadastradoPorBaseSql, idDestinatarioCadastradoPorBaseSql, idTransportadorCadastradoPorBaseSql); _notaFiscalValida.Destinatario = _destinatarioRepositorio.BuscarPorId(idDestinatarioCadastradoPorBaseSql); _notaFiscalValida.Emitente = _emitenteRepositorio.BuscarPorId(idEmitenteCadastradoPorBaseSql); _notaFiscalValida.Transportador = _transportadorRepositorio.BuscarPorId(idTransportadorCadastradoPorBaseSql); _notaFiscalValida.Produtos = new List <ProdutoNotaFiscal>(); _notaFiscalValida.Produtos.Add(_produtoNotaFiscalRepositorioSql.BuscarPorId(idProdutoNotaFiscalCadastradorPorBaseSql)); _notaFiscalValida.CalcularValoresTotais(); _notaFiscalValida.GerarChaveDeAcesso(new Random()); _notaFiscalValida.DataEmissao = DateTime.Now; }
public void ShouldLogCustomerApplication() { using (var db = new FakeDbContext()) { var dateTime = new FakeDateTimeService(new DateTime(2020, 2, 8)); var ipAddressService = new FakeClientIpAddressService("192.168.0.1"); var sut = new LogCustomerApplicationHandler(db, dateTime, ipAddressService); var command = new LogCustomerApplication { FirstName = "Joe", LastName = "Bloggs", DateOfBirth = new DateTime(1980, 1, 1), AnnualIncome = 30000, RecommendedCards = new[] { "BarclayCard" } }; sut.Handle(command); var applications = db.CustomerApplications.ToArray(); Assert.Single(applications); var first = applications.First(); Assert.Equal(command.FirstName, first.FirstName); Assert.Equal(command.LastName, first.LastName); Assert.Equal(command.DateOfBirth, first.DateOfBirth); Assert.Equal(command.AnnualIncome, first.AnnualIncome); Assert.Equal(string.Join(",", command.RecommendedCards), first.RecommendedCards); Assert.Equal(dateTime.Now, first.CreatedDate); Assert.Equal("192.168.0.1", first.IpAddress); } }
public void Dispose() { using (var context = new FakeDbContext(_options)) { context.Database.EnsureDeleted(); } }
public void Should_Delete_Entity_With_Entity_Object() { var options = DatabaseOptionsWithData <FakeDbContext>(typeof(FakeDbContext)); var fakeEntities = new FakeEntities(); var fakeEntity = fakeEntities[0]; using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var entityToDelete = repository.Select(prop => prop.EntityCode == fakeEntity.EntityCode).Single(); repository.Delete(entityToDelete); var saveCount = repository.SaveChanges(); Assert.Equal(1, saveCount); } using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var result = repository.Select(); var singleResult = result.Single(prop => prop.EntityCode == fakeEntity.EntityCode); Assert.Equal(fakeEntities.Count, result.Count()); Assert.True(singleResult.IsDeleted); Assert.True(singleResult.DeletedTime == singleResult.ModifiedTime); Assert.True(singleResult.ModifiedTime > singleResult.CreatedTime); Assert.Equal(Principal.Identity.Name, singleResult.ModifiedBy); } }
public async Task Should_Delete_Entities_Async() { var options = DatabaseOptionsWithData <FakeDbContext>(typeof(FakeDbContext)); var fakeEntities = new FakeEntities(); var fakeEntity = fakeEntities[0]; using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var entitiesToDelete = await repository.SelectAsync(); await repository.DeleteAsync(entitiesToDelete); var saveCount = await repository.SaveChangesAsync(); Assert.Equal(entitiesToDelete.Count(), saveCount); } using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var result = await repository.SelectAsync(); var singleResult = result.Single(prop => prop.EntityCode == fakeEntity.EntityCode); Assert.Equal(fakeEntities.Count, result.Count()); Assert.All(result, prop => Assert.True(prop.IsDeleted)); Assert.All(result, prop => Assert.True(prop.DeletedTime == prop.ModifiedTime)); Assert.All(result, prop => Assert.True(prop.ModifiedTime > prop.CreatedTime)); Assert.All(result, prop => Assert.Equal(Principal.Identity.Name, prop.ModifiedBy)); } }
public async Task Should_Select_Entity_With_Primary_Key_Async() { var options = DatabaseOptionsWithData <FakeDbContext>(typeof(FakeDbContext)); var fakeEntities = new FakeEntities(); var entityToSearch = fakeEntities[2]; using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); entityToSearch = repository.Select(prop => prop.EntityCode == entityToSearch.EntityCode).Single(); } using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var result = await repository.SelectAsync(entityToSearch.Id); Assert.NotNull(result); Assert.True(result.Id > 0); Assert.Contains(fakeEntities, prop => prop.EntityCode == result.EntityCode); Assert.Contains(fakeEntities, prop => prop.EntityName == result.EntityName); } }
public async Task Should_Insert_Entities_Async() { var options = DatabaseOptions <FakeDbContext>(); var fakeEntities = new FakeEntities(); fakeEntities.ForEach(entity => entity.FakeChildEntities = null); using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var result = await repository.InsertAsync(fakeEntities); var saveCount = await repository.SaveChangesAsync(); Assert.True(result.Count() > 0); Assert.All(result, prop => Assert.True(prop.Id > 0)); Assert.Equal(fakeEntities.Count, saveCount); } using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var result = await repository.SelectAsync(); var entryDateTime = result.First().CreatedTime; Assert.Equal(fakeEntities.Count, result.Count()); Assert.All(result, prop => Assert.True(prop.Id > 0)); Assert.All(result, prop => Assert.Equal(Principal.Identity.Name, prop.CreatedBy)); Assert.All(result, prop => Assert.Equal(entryDateTime, prop.CreatedTime, TimeSpan.FromMinutes(1))); } }
public async void IsByUserShouldReturnFalseWhenTheUserDoesntHaveArticleWithGivenArticleId() { // ARRANGE const int articleId = 1; const string userId = "10000"; const string database = "IsByUserShouldReturnFalseWhenTheUserDoesntHaveArticleWithGivenArticleId"; await using (var context = new FakeDbContext(database)) { await context.SeedArticles(3); } // ACT bool result; await using (var context = new FakeDbContext(database)) { var articleService = new ArticleService(context, null, null); result = await articleService.IsByUser(articleId, userId); } // ASSERT Assert.False(result); }
public async Task ChangeVisibilityShoulSetCorrectPublishedOnDate() { // arrange await using FakeDbContext context = new FakeDbContext("ChangeVisibilityShoulSetCorrectPublishedOnDate"); await context.SeedArticles(1); var dateTimeService = new FakeDateTimeService(); dateTimeService.DateTime = new DateTime(2001, 1, 1, 1, 1, 1); var service = new ArticleService( context, null, dateTimeService); // act await service.ChangeVisibility(1); await using FakeDbContext context2 = new FakeDbContext("ChangeVisibilityShoulSetCorrectPublishedOnDate"); var article = await context2.Articles.FirstOrDefaultAsync(t => t.Id == 1); Assert.Equal(dateTimeService.DateTime, article.PublishedOn); }
public void Should_Audit_When_EntityState_SoftDeleted() { var options = DatabaseOptions <FakeDbContext>(); var fakeEntities = new FakeEntities(); using (IDbContext context = new FakeDbContext(options)) { var dbSet = context.Set <FakeEntity>(); dbSet.AddRange(fakeEntities); context.SaveChanges(); } using (IDbContext context = new FakeDbContext(options)) { var dbSet = context.Set <FakeEntity>(); dbSet.RemoveRange(fakeEntities); context.Audit(); var auditEntries = context.GetCurrentEntries(); Assert.All(auditEntries, prop => Assert.Equal(Principal.Identity.Name, prop.CurrentValues[nameof(FakeEntity.ModifiedBy)])); Assert.All(auditEntries, prop => Assert.True((bool)prop.CurrentValues[nameof(FakeEntity.IsDeleted)])); Assert.All(auditEntries, prop => Assert.Equal((DateTime)prop.CurrentValues[nameof(FakeEntity.ModifiedTime)], (DateTime)prop.CurrentValues[nameof(FakeEntity.DeletedTime)], TimeSpan.FromMinutes(1))); } }
public async void IsByUserShouldReturnTrueWhenArticleByTheSpecificUserExists() { // ARRANGE const int articleId = 1; const string userId = "1"; const string database = "IsByUserShouldReturnTrueWhenArticleByTheSpecificUserExists"; await using (var context = new FakeDbContext(database)) { await context.SeedArticles(3); } // ACT bool result; await using (var context = new FakeDbContext(database)) { var articleService = new ArticleService(context, null, null); result = await articleService.IsByUser(articleId, userId); } // ASSERT Assert.True(result); }
public void Should_Audit_When_EntityState_Modified() { var options = DatabaseOptions <FakeDbContext>(); var fakeEntities = new FakeEntities(); using (IDbContext context = new FakeDbContext(options)) { var dbSet = context.Set <FakeEntity>(); dbSet.AddRange(fakeEntities); context.SaveChanges(); } using (IDbContext context = new FakeDbContext(options)) { var dbSet = context.Set <FakeEntity>(); dbSet.AttachRange(fakeEntities); fakeEntities.ForEach(entity => entity.EntityName = "Modified"); context.Audit(); var auditEntries = context.GetCurrentEntries(); var modifyDateTime = (DateTime)auditEntries.First().CurrentValues[nameof(FakeEntity.ModifiedTime)]; Assert.All(auditEntries, prop => Assert.Equal("Modified", prop.CurrentValues[nameof(FakeEntity.EntityName)])); Assert.All(auditEntries, prop => Assert.Equal(Principal.Identity.Name, prop.CurrentValues[nameof(FakeEntity.ModifiedBy)])); Assert.All(auditEntries, prop => Assert.Equal(modifyDateTime, (DateTime)prop.CurrentValues[nameof(FakeEntity.ModifiedTime)], TimeSpan.FromMinutes(1))); } }
public void Thrown_Exception_On_Generate_Create_Script_Non_Relational_Database() { using (IDbContext context = new FakeDbContext(DatabaseOptions <FakeDbContext>())) { Assert.Throws <InvalidOperationException>(() => context.GenerateCreateScript()); } }
/// <inheritdoc /> public async Task <int?> Handle(FakeCrudAddCommand request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } using (var dbContext = new FakeDbContext(_fakeDbContextOptions)) { var entity = new FakeAddAuditDbSet { Value = request.RequestDto, Created = DateTimeOffset.UtcNow }; _ = dbContext.FakeAddAudit.Add(entity); var saveResult = await dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false); #pragma warning disable CA1848 // Use the LoggerMessage delegates this._logger.LogDebug("DbContext Save Result: {SaveResult}", saveResult); #pragma warning restore CA1848 // Use the LoggerMessage delegates } return(await Task.FromResult(request.RequestDto).ConfigureAwait(false)); }
public void Query_Tracking_Behavior_Default_To_Track_All() { var options = DatabaseOptionsWithData <FakeDbContext>(typeof(FakeDbContext)); var fakeEntities = new FakeEntities(); var fakeEntity = fakeEntities[0]; using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var entityToUpdate = repository.Select(prop => prop.EntityCode == fakeEntity.EntityCode).Single(); entityToUpdate.EntityName = "Modified"; var saveCount = repository.SaveChanges(); Assert.Equal(1, saveCount); } using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var result = repository.Select(); var singleResult = result.Single(prop => prop.EntityCode == fakeEntity.EntityCode); Assert.Equal(fakeEntities.Count, result.Count()); Assert.Equal("Modified", singleResult.EntityName); Assert.Equal(Principal.Identity.Name, singleResult.ModifiedBy); Assert.True(singleResult.ModifiedTime > singleResult.CreatedTime); } }
public void SetUp() { this.fakeDbContext = new FakeDbContext(); this.startPoint = new MapPoint(35.048072199999979, 48.437927).ToSqlGeography(); this.endPoint = new MapPoint(35.045630999999958, 48.46442).ToSqlGeography(); this.route = new RouteSeach(); }
public void EF_Diagnostics_Success_Test() { var processorObserver = new TracingDiagnosticProcessorObserver(new[] { new EntityFrameworkCoreDiagnosticProcessor() }); DiagnosticListener.AllListeners.Subscribe(processorObserver); using (var tracerContextListener = new FakeIgnoreTracerContextListener()) { try { using (var dbContext = new FakeDbContext(_options)) { dbContext.Users.Add(new FakeUser("Zhang", "San")); dbContext.SaveChanges(); } } catch { // ignored } Assert.Equal(1, tracerContextListener.Counter); } }
public void InsertGraphForNewAggregateRootEntityAndChildrenUsingConvention() { // Arrange FakeDbContext dbContext = new FakeDbContext(); AggregateRootEntityRepository entityRepository = new AggregateRootEntityRepository(dbContext); AggregateRootEntity aggregateRootEntity = new AggregateRootEntity { SomeOtherProperty = "Some other property", SimpleEntity = new SimpleEntity { SomeProperty = "Some property" }, OtherSimpleEntities = new List <AnotherSimpleEntity> { new AnotherSimpleEntity { SomeProperty = "Child property 1" }, new AnotherSimpleEntity { SomeProperty = "Child property 2" }, } }; // Act entityRepository.InsertOrUpdateGraph(aggregateRootEntity); // Assert Assert.IsNotNull(entityRepository.DbContext); // The AggregateRoot and its children should all be added to the context and all have a state of 'Added' Assert.AreEqual(4, entityRepository.DbContext.ChangeTracker.Entries().Count()); entityRepository.DbContext.ChangeTracker.Entries().ToList().ForEach(entry => Assert.AreEqual(EntityState.Added, entry.State)); }
public async Task Should_Insert_Entity_Async() { var options = DatabaseOptions <FakeDbContext>(); var fakeEntity = new FakeEntities()[0]; fakeEntity.FakeChildEntities = null; using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var result = await repository.InsertAsync(fakeEntity); var saveCount = await repository.SaveChangesAsync(); Assert.True(result.Id > 0); Assert.Equal(1, saveCount); } using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var result = await repository.SelectAsync(prop => prop.EntityCode == fakeEntity.EntityCode); Assert.Single(result); Assert.True(result.First().Id > 0); Assert.True(result.First().EntityCode == fakeEntity.EntityCode); Assert.True(result.First().EntityName == fakeEntity.EntityName); Assert.Equal(Principal.Identity.Name, result.First().CreatedBy); Assert.True(result.First().CreatedTime > DateTime.MinValue); } }
public void DbContext_Init_Success_Test() { using (var dbContext = new FakeDbContext(_options)) { Assert.NotNull(dbContext); } }
public async Task Should_Update_Entities_Async() { var options = DatabaseOptionsWithData <FakeDbContext>(typeof(FakeDbContext)); var fakeEntities = new FakeEntities(); using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var entitiesToUpdate = (await repository.SelectAsync()).ToList(); entitiesToUpdate.ForEach(entity => entity.EntityName = "Modified"); var result = await repository.UpdateAsync(entitiesToUpdate); var saveCount = await repository.SaveChangesAsync(); Assert.All(entitiesToUpdate, prop => Assert.True(prop.Id > 0)); Assert.Equal(entitiesToUpdate.Count, saveCount); } using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var result = await repository.SelectAsync(); Assert.Equal(fakeEntities.Count, result.Count()); Assert.All(result, prop => Assert.Equal("Modified", prop.EntityName)); Assert.All(result, prop => Assert.Equal(Principal.Identity.Name, prop.ModifiedBy)); Assert.All(result, prop => Assert.True(prop.ModifiedTime > prop.CreatedTime)); } }
public void Should_Delete_Entities() { var options = DatabaseOptionsWithData <FakeDbContext>(typeof(FakeDbContext)); var fakeEntities = new FakeEntities(); using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var entitiesToDelete = repository.Select(); repository.Delete(entitiesToDelete); var saveCount = repository.SaveChanges(); Assert.Equal(entitiesToDelete.Count(), saveCount); } using (IDbContext context = new FakeDbContext(options)) { var repository = new Repository <FakeEntity>(context); var result = repository.Select(); Assert.Equal(fakeEntities.Count, result.Count()); Assert.All(result, prop => Assert.True(prop.IsDeleted)); Assert.All(result, prop => Assert.True(prop.DeletedTime == prop.ModifiedTime)); Assert.All(result, prop => Assert.True(prop.ModifiedTime > prop.CreatedTime)); Assert.All(result, prop => Assert.Equal(Principal.Identity.Name, prop.ModifiedBy)); } }
public void InsertAggregateRootEntity() { // Arrange const int expectedSimpleId = 10; const int expectedAggregateRootId = 20; FakeDbContext dbContext = new FakeDbContext(); AggregateRootEntityRepository entityRepository = new AggregateRootEntityRepository(dbContext); AggregateRootEntity aggregateRootEntity = new AggregateRootEntity { Id = expectedAggregateRootId, SimpleEntity = new SimpleEntity { Id = expectedSimpleId } }; // Act entityRepository.Insert(aggregateRootEntity); // Assert Assert.IsNotNull(entityRepository.DbContext); // Both the AggregateRoot and its child SimpleEntity should be added to the context, but only the aggregate root // should have an added state Assert.AreEqual(2, entityRepository.DbContext.ChangeTracker.Entries().Count()); Assert.AreEqual(EntityState.Added, entityRepository.DbContext.FindEntity(expectedAggregateRootId).State); Assert.AreEqual(EntityState.Unchanged, entityRepository.DbContext.FindEntity(expectedSimpleId).State); }
public void CreatingDataWillAdd50Theses() { var fakeDbContext = new FakeDbContext(); var faculties = fakeDbContext.Theses.ToList(); var expected = 50; var actual = faculties.Count(); Assert.AreEqual(expected, actual); }
public void CreatingDataWillAdd50Students() { var fakeDbContext = new FakeDbContext(); var actual = fakeDbContext.Users.Where(u => u.Student != null).Count(); var expected = 50; Assert.AreEqual(expected, actual); }
public void CreatingDataWillAdd5Faculties() { var fakeDbContext = new FakeDbContext(); var actual = fakeDbContext.Faculties.Count(); var expected = 5; Assert.AreEqual(expected, actual); }
public void AddingASpecialtyWillIncreaseSpecialtyCount() { var fakeDbContext = new FakeDbContext(); fakeDbContext.Faculties.Add(new Faculty { Title = "new" }); var actual = fakeDbContext.Faculties.Count(); var expected = 6; Assert.AreEqual(expected, actual); }
public void CanMakeValidRoute() { var context = new FakeDbContext(); var routes = new List<Route>(); var route = FakeRepository<Route>.Mock(fakeDbContext.Routes).All(); routes.Add(route.First()); var result = ModelConverter.Convert(routes); Assert.NotNull(result); }
public void CanMakeValidRoute() { var context = new FakeDbContext(); var unitOfWork = new FakeUnitOfWork(context); var routes = new List<Route>(); var route = unitOfWork.RouteRepository.All(); routes.Add(route.First()); var result = Route.MakeValid(routes); Assert.NotNull(result); }
public void CreatingDataWillAdd5SPecialtiesForEveryFaculty() { var fakeDbContext = new FakeDbContext(); var faculties = fakeDbContext.Faculties.ToList(); foreach (var faculty in faculties) { var expected = 5; var actual = 5; Assert.AreEqual(expected, actual); } }
public void Setup() { _db = new FakeDbContext(); _db.Restaurants = new[] { new Restaurant() {ID = 1, Name = "Restoran 1"}, new Restaurant() {ID = 2, Name = "Restoran 2"}, new Restaurant() {ID = 3, Name = "Restoran 3"}, new Restaurant() {ID = 4, Name = "Restoran 4"}, new Restaurant() {ID = 5, Name = "Restoran 5"} }.AsQueryable(); _db.Reviews = new[] { new Review(){ID = 1, RestaurantID = 1, Body = "SSS",DiningDate = new DateTime(2015,2,13),Rating = 9}, new Review(){ID = 2, RestaurantID = 2, Body = "SSSas32",DiningDate = new DateTime(2014,11,7),Rating = 3}, new Review(){ID = 3, RestaurantID = 3, Body = "SassaSS",DiningDate = new DateTime(2015,5,24),Rating = 6}, new Review(){ID = 4, RestaurantID = 1, Body = "asfasd" ,DiningDate = new DateTime(2010,2,8),Rating = 10} }.AsQueryable(); }
public void UpdatingSpecialtyTitleWontThrowException() { var fakeDbContext = new FakeDbContext(); var specialty = fakeDbContext.Specialties.FirstOrDefault(); specialty.Title = "KST"; fakeDbContext.SaveChanges(); var expected = "KST"; var actual = specialty.Title; Assert.AreEqual(expected, actual); }
public void SetUp() { this.fakeDbContext = new FakeDbContext(); this.autocomplete = new DomainAutocomplete.Autocomplete(FakeRepository<Place>.Mock(fakeDbContext.Places), FakeRepository<Building>.Mock(fakeDbContext.Buildings)); }
public void CreatingDataToDbSetWontThrowException() { var fakeDbContext = new FakeDbContext(); var fakeData = new FakeData(fakeDbContext); }
public void DeletingThesisWillDecreaseThesesCount() { var fakeDbContext = new FakeDbContext(); var thesis = fakeDbContext.Theses.FirstOrDefault(); fakeDbContext.Theses.Remove(thesis); fakeDbContext.SaveChanges(); var expected = 49; var actual = fakeDbContext.Theses.Count(); Assert.AreEqual(expected, actual); }
public void SetUpTest() { this.fakeDbContext = new FakeDbContext(); this.addRouteController = new AddRouteController(FakeRepository<Route>.Mock(fakeDbContext.Routes), FakeRepository<Stop>.Mock(fakeDbContext.Stops)); }
public void SetUpTests() { this.fakeDbContext = new FakeDbContext(); }