public void Delete_Log_test() { // --========================================================================================================== Arrangement // Идентификатор пользователя удаляющего запись _entity.LogUser_Id = 123453; // --========================================================================================================== Action EntityService.Delete(_entity); var entityFromBase = EntityService.LoadEntityOrNull(_entity.Id); Assert.IsNull(entityFromBase); // --========================================================================================================== Assertion LoggingLogEntity logEntity = null; using (DataConnection context = new DataConnection("Core")) { // Получаем залогированную сущность logEntity = context.GetTable <LoggingLogEntity>().Single(log => log.ActionLog == "Delete" && log.IdLog == _entity.Id); } Assert.AreEqual(logEntity.UserIdLog, 123453); Assert.AreEqual("Delete", logEntity.ActionLog); //--------------------------------------- Все бизнес свойсва должны быть заполены так же как перед удалением. Assert.AreEqual("NewName", logEntity.Name); Assert.AreEqual(2000, logEntity.Year); Assert.AreEqual(new DateTime(2012, 11, 11), logEntity.BirthDate); Assert.AreEqual(1200, logEntity.Amount); }
public void Insert_Log_Test() { // --========================================================================================================== Action EntityService.Insert(_entity = new LoggingEntity { Id = 3, Name = "SomeName", Year = 100, BirthDate = new DateTime(1982, 5, 2), Amount = 1200, LogUser_Id = 1000, NullableName = null }); // --========================================================================================================== Assertion var entityFromBase = EntityService.LoadEntity(_entity.Id); Assert.AreEqual("SomeName", entityFromBase.Name); Assert.AreEqual(100, entityFromBase.Year); Assert.AreEqual(new DateTime(1982, 5, 2), entityFromBase.BirthDate); Assert.AreEqual(1200, entityFromBase.Amount); LoggingLogEntity logEntity = null; using (DataConnection context = new DataConnection("Core")) { // Получаем залогированную сущность logEntity = context.GetTable <LoggingLogEntity>().Single(item => item.IdLog == _entity.Id); } Assert.AreEqual("Insert", logEntity.ActionLog); Assert.AreEqual("SomeName", logEntity.Name); Assert.AreEqual(100, logEntity.Year); Assert.AreEqual(new DateTime(1982, 5, 2), logEntity.BirthDate); Assert.AreEqual(1200, logEntity.Amount); Assert.AreEqual(1000, logEntity.UserIdLog); Assert.AreEqual(null, logEntity.NullableName); }
public void Update_Log_Test() { // --========================================================================================================== Assigement _entity.Name = "NewName"; _entity.Year = 2000; _entity.BirthDate = new DateTime(2012, 11, 11); _entity.LogUser_Id = 1234; // --========================================================================================================== Action EntityService.Update(_entity); // --========================================================================================================== Assertion var entityFromBase = EntityService.LoadEntity(_entity.Id); Assert.AreEqual("NewName", entityFromBase.Name); Assert.AreEqual(2000, entityFromBase.Year); Assert.AreEqual(new DateTime(2012, 11, 11), entityFromBase.BirthDate); Assert.AreEqual(1200, entityFromBase.Amount); LoggingLogEntity logEntity = null; using (DataConnection context = new DataConnection("Core")) { // Получаем залогированную сущность logEntity = context.GetTable <LoggingLogEntity>().Single(log => log.ActionLog == "Update" && log.IdLog == _entity.Id); } Assert.AreEqual("Update", logEntity.ActionLog); Assert.AreEqual("NewName", logEntity.Name); Assert.AreEqual(2000, logEntity.Year); Assert.AreEqual(new DateTime(2012, 11, 11), logEntity.BirthDate); Assert.AreEqual(1200, logEntity.Amount); Assert.AreEqual(1234, logEntity.UserIdLog); }