public void Repository_Can_Remove_ById()
        {
            using (var context = new InMemoryContext())
                using (IRepository <TabelaTesteWithGuidKey, Guid> repository = new TabelaTesteWithGuidKeyRepository(context, GetUserContextService()))
                {
                    var uow = new UnityOfWork(context, Substitute.For <ILogProvider>());

                    var registro = new TabelaTesteWithGuidKey()
                    {
                        Propriedade = Guid.NewGuid().ToString()
                    };

                    repository.AddOrUpdate(registro);

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

                    repository.Remove(registro.Id);
                    uow.SaveAndCommit();
                    Assert.IsTrue(alteracoes == 1);

                    registro = repository.Find(p => p.Id == registro.Id).FirstOrDefault();
                    Assert.Null(registro);
                }
        }
        public void Repository_Can_Update_Attached()
        {
            using (var context = new InMemoryContext())
                using (IRepository <TabelaTesteWithGuidKey, Guid> repository = new TabelaTesteWithGuidKeyRepository(context, GetUserContextService()))
                {
                    var uow = new UnityOfWork(context, Substitute.For <ILogProvider>());

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

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

                    var registro = repository.GetAll().FirstOrDefault();
                    Assert.NotNull(registro);
                    Assert.IsTrue(registro.Id != Guid.Empty);

                    registro.Propriedade = "Alterada_123";

                    repository.AddOrUpdate(registro);
                    uow.SaveAndCommit();
                    Assert.IsTrue(alteracoes == 1);
                    Assert.AreEqual(registro.Propriedade, "Alterada_123");
                }
        }
        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");
                }
        }