Ejemplo n.º 1
0
        public void Send_Taking_Several_Logs_Saves_Log_In_Db_Context()
        {
            var options = new DbContextOptionsBuilder <LogModelContext>()
                          .UseInMemoryDatabase(databaseName: "Test2")
                          .Options;
            var logDataContext = new LogModelContext(options);
            IDbContextProvider         dbContextProvider          = new DbContextProvider(logDataContext);
            IDbEntityBuilder           dbEntityBuilder            = new LogDbModelEntityBuilder();
            EntityFrameworkDestination entityFrameworkDestination = new EntityFrameworkDestination(dbContextProvider, dbEntityBuilder);
            LogModel logData1 = Samples.LogModels.WithTagsAndItems(LogType.Warning);

            logData1.LogId = "LogId1";
            LogModel logData2 = Samples.LogModels.WithTagsAndItems(LogType.Error);

            logData2.LogId = "LogId2";
            LogModel logData3 = Samples.LogModels.WithTagsAndItems(LogType.Info);

            logData3.LogId = "LogId3";

            // Act
            entityFrameworkDestination.Send(new LogModel[] { logData1, logData2, logData3 });

            // Assert
            List <LogDbModel> logs = logDataContext.Logs.ToList();

            Assert.AreEqual(3, logs.Count);
            LogDbModelAsserts.AssertLogModelModelIsEqualToLogModel(logs[0], logData1);
            LogDbModelAsserts.AssertLogModelModelIsEqualToLogModel(logs[1], logData2);
            LogDbModelAsserts.AssertLogModelModelIsEqualToLogModel(logs[2], logData3);
        }
Ejemplo n.º 2
0
        public void BuildDbEntity_When_Called_Creates_And_Returns_LogDbModel()
        {
            // Arrange
            LogDbModelEntityBuilder logDbModelEntityBuilder = new LogDbModelEntityBuilder();
            LogModel logData = Samples.LogModels.WithTagsAndItems();

            // Act
            Object logDbModel = logDbModelEntityBuilder.BuildDbEntity(logData);

            // Assert
            Assert.IsInstanceOf <LogDbModel>(logDbModel);
            LogDbModelAsserts.AssertLogModelModelIsEqualToLogModel((LogDbModel)logDbModel, logData);
        }
Ejemplo n.º 3
0
        public void BuildDbEntity_When_Called_Given_That_Tags_And_LogItems_Are_Null()
        {
            // Arrange
            LogDbModelEntityBuilder logDbModelEntityBuilder = new LogDbModelEntityBuilder();
            LogModel logData = Samples.LogModels.Standard();

            logData.Tags     = null;
            logData.LogItems = null;

            // Act
            Object dbModelObj = logDbModelEntityBuilder.BuildDbEntity(logData);

            // Assert
            LogDbModelAsserts.AssertLogModelModelIsEqualToLogModel((LogDbModel)dbModelObj, logData);
        }
Ejemplo n.º 4
0
        public void Send_Taking_One_Log_Saves_Log_In_Db_Context()
        {
            var options = new DbContextOptionsBuilder <LogModelContext>()
                          .UseInMemoryDatabase(databaseName: "Test1")
                          .Options;
            var logDataContext = new LogModelContext(options);
            IDbContextProvider         dbContextProvider          = new DbContextProvider(logDataContext);
            IDbEntityBuilder           dbEntityBuilder            = new LogDbModelEntityBuilder();
            EntityFrameworkDestination entityFrameworkDestination = new EntityFrameworkDestination(dbContextProvider, dbEntityBuilder);
            LogModel logData = Samples.LogModels.WithTagsAndItems();

            // Act
            entityFrameworkDestination.Send(new LogModel[] { logData });

            // Assert
            List <LogDbModel> logs = logDataContext.Logs.ToList();

            Assert.AreEqual(1, logs.Count);
            LogDbModelAsserts.AssertLogModelModelIsEqualToLogModel(logs[0], logData);
        }