예제 #1
0
        public async Task Index_ReturnsAllStrategies()
        {
            // Arrange
            var strategyModel = new StrategyConciseViewModel()
            {
                Id = 1, Title = "First"
            };
            bool methodCalled = false;

            var mockRepository = new Mock <IAdminStrategiesService>();

            mockRepository.Setup(s => s.GetAllStrategiesAsync())
            .ReturnsAsync(new[] { strategyModel })
            .Callback(() => methodCalled = true);

            var controller = new StrategiesController(mockRepository.Object);

            // Act
            var result = await controller.Index();

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            var resultView = result as ViewResult;

            Assert.IsNotNull(resultView.Model);
            Assert.IsInstanceOfType(resultView.Model, typeof(IEnumerable <StrategyConciseViewModel>));
            Assert.IsTrue(methodCalled);
        }
        public void Add_WithValidStrategy_ShouldCallService()
        {
            // Arrange
            var  model          = new StrategyCreationBindingModel();
            bool serviceCalled  = false;
            var  mockRepository = new Mock <IAdminStrategiesService>();

            mockRepository.Setup(repo => repo.AddStrategyAsync(model))
            .Callback(() => serviceCalled = true);

            var controller = new StrategiesController(mockRepository.Object);

            // Act
            var result = controller.Add(model);

            // Assert
            Assert.IsTrue(serviceCalled);
        }