Exemplo n.º 1
0
        public async Task Management_ReturnsAViewResult_WithAboutMeModel()
        {
            //Arrange
            var technologyLogicMock = new Mock <ITechnologyLogic>();

            var aboutMeLogicMock = new Mock <IAboutMeLogic>();
            var modelToReturn    = new AboutMe()
            {
                AboutMeId = 1, ImageLink = "link", Title = "Title", Text = "Text"
            };

            aboutMeLogicMock.Setup(logic => logic.GetAboutMeAsync()).ReturnsAsync(modelToReturn);

            AboutMeController controllerUnderTests = new AboutMeController(aboutMeLogicMock.Object, technologyLogicMock.Object);


            //Act
            var result = await controllerUnderTests.Management();

            //Assert
            var viewResult    = Assert.IsType <ViewResult>(result);
            var returnedModel = Assert.IsAssignableFrom <AboutMe>(viewResult.ViewData.Model);

            ComparisonResult res = MyComparer.Compare(modelToReturn, returnedModel);

            Assert.True(res.AreEqual);
        }
Exemplo n.º 2
0
        public async Task Management_RedirectToErrorPage_WhenModelIsNull()
        {
            //Arrange
            var technologyLogicMock = new Mock <ITechnologyLogic>();

            var aboutMeLogicMock = new Mock <IAboutMeLogic>();

            aboutMeLogicMock.Setup(logic => logic.GetAboutMeAsync()).ReturnsAsync((AboutMe)null);

            AboutMeController controllerUnderTests = new AboutMeController(aboutMeLogicMock.Object, technologyLogicMock.Object);

            //Act
            var result = await controllerUnderTests.Management();

            //Assert
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal("Error", viewResult.ViewName);
        }