public void Update_InsertOneAgreementThenUpdate_SetChangeDateAndChangedBy()
        {
            var agreement = new Agreement {
                Date = new DateTime(2020, 05, 01), Number = "1"
            };

            using (var dbContext = new TestDbContext())
            {
                var repository = new AgreementWriteRepository(dbContext);

                repository.Add(agreement);
                repository.SaveChanges();
                var identityProvider = new Mock <IIdentityProvider>();
                identityProvider.Setup(a => a.User).Returns("TestUser");

                var writeTrackingEntityRepository = new WriteTrackingEntityRepository <Agreement, int>(repository, identityProvider.Object);
                writeTrackingEntityRepository.Update(a => a.Id == agreement.Id, a => new Agreement {
                    Number = "123"
                });
            }

            using (var dbContext = new TestDbContext())
            {
                var updatedAgreement = dbContext.Set <Agreement>().Single(a => a.Id == agreement.Id);

                Assert.AreEqual("TestUser", updatedAgreement.ChangedBy);
                Assert.IsNotNull(updatedAgreement.ChangeDate);
                Assert.AreEqual("123", updatedAgreement.Number);
            }
        }
        public void DeleteByExpression_InsetOneThenSoftDelete_SetIsDeleted()
        {
            var agreement = new Agreement {
                Date = new DateTime(2020, 05, 01), Number = "1"
            };

            using (var dbContext = new TestDbContext())
            {
                var repository = new AgreementWriteRepository(dbContext);

                repository.Add(agreement);
                repository.SaveChanges();
                var identityProvider = new Mock <IIdentityProvider>();
                identityProvider.Setup(a => a.User).Returns("TestUser");

                var writeTrackingEntityRepository = new WriteTrackingEntityRepository <Agreement, int>(repository, identityProvider.Object);
                writeTrackingEntityRepository.Delete(a => a.Id == agreement.Id);
            }

            using (var dbContext = new TestDbContext())
            {
                var updatedAgreement = dbContext.Set <Agreement>().Single(a => a.Id == agreement.Id);
                Assert.IsTrue(updatedAgreement.IsDeleted);
            }
        }
        public static Agreement AddAgreement(string number = "1", DateTime?date = null)
        {
            var agreement = new Agreement {
                Date = date ?? new DateTime(2020, 05, 01), Number = number
            };

            using (var dbContext = new TestDbContext())
            {
                var repository = new AgreementWriteRepository(dbContext);

                repository.Add(agreement);
                repository.SaveChanges();
            }

            return(agreement);
        }