コード例 #1
0
        public void LogActionAddsRecordToDatabase()
        {
            var options = new DbContextOptionsBuilder <ActionDbContext>()
                          .UseInMemoryDatabase(databaseName: "ActionTestDb")
                          .Options;

            int numberOfActionsBeforeLogging;

            using (var context = new ActionDbContext(options))
            {
                context.AddRange(ActionMemoryDb.GetTestActions());
                context.SaveChanges();
                numberOfActionsBeforeLogging = context.Actions.ToList().Count;
            }

            int numberOfActionsAfterLogging;

            using (var context = new ActionDbContext(options))
            {
                ActionRepository actionRepository = new ActionRepository(context);
                var logger = new DatabaseLogger(actionRepository);
                logger.LogAction("TestAction", "TestInput", "TestOutput");
                numberOfActionsAfterLogging = actionRepository.GetActions().Count;
            }

            Assert.Equal(numberOfActionsBeforeLogging + 1, numberOfActionsAfterLogging);
        }
コード例 #2
0
        public async void GetActionsReturnsListOfActions()
        {
            var mockRepo = new Mock <IActionAsyncRepository>();

            mockRepo.Setup(repo => repo.GetActionsAsync()).ReturnsAsync(ActionMemoryDb.GetTestActions());
            var controller = new ActionsController(mockRepo.Object);

            var actions = await controller.GetActions();

            Assert.Equal(ActionMemoryDb.GetTestActions().Count, actions.Count);
        }