コード例 #1
0
        public void Repository_Can_Update_Attached()
        {
            using (var context = new InMemoryContext())
            {
                IRepository <TabelaTesteWithLongKey, long> repository = new TabelaTesteWithLongKeyRepository(context, GetUserContextService());
                var uow = new UnitOfWork(context, Substitute.For <ILogger <UnitOfWork> >());

                repository.AddOrUpdate(new TabelaTesteWithLongKey()
                {
                    Propriedade = Guid.NewGuid().ToString()
                });

                var alteracoes = uow.SaveAndCommit();
                Assert.IsTrue(alteracoes == 1);

                var registro = repository.GetAll().FirstOrDefault();
                Assert.NotNull(registro);
                Assert.IsTrue(registro.Id > 0);

                registro.Propriedade = "Alterada_123";

                repository.AddOrUpdate(registro);
                uow.SaveAndCommit();
                Assert.IsTrue(alteracoes == 1);
                Assert.AreEqual(registro.Propriedade, "Alterada_123");
            }
        }
コード例 #2
0
        public void Repository_Can_Insert()
        {
            using (var context = new InMemoryContext())
                using (IRepository <TabelaTesteWithLongKey, long> repository = new TabelaTesteWithLongKeyRepository(context, GetUserContextService()))
                {
                    var uow = new UnityOfWork(context, Substitute.For <ILogProvider>());

                    repository.AddOrUpdate(new TabelaTesteWithLongKey()
                    {
                        Propriedade = Guid.NewGuid().ToString()
                    });

                    var alteracoes = uow.SaveAndCommit();
                    Assert.IsTrue(alteracoes == 1);

                    var chave = repository.GetAll().FirstOrDefault();
                    Assert.NotNull(chave);
                    Assert.IsTrue(chave.Id > 0);

                    var registro = repository.GetById(chave.Id);
                    Assert.NotNull(registro);

                    registro.Propriedade = "Alterada";
                    uow.SaveAndCommit();

                    registro = repository.GetById(chave.Id);
                    Assert.NotNull(registro);
                    Assert.AreEqual(registro.Propriedade, "Alterada");
                }
        }