Beispiel #1
0
        public void Add_should_return_correct_view_and_model()
        {
            // given
            const string expectedFilename = "This is Wayne's filename";
            var          expectedTestFile = new TestFile();

            _testServiceMock
            .Setup(x => x.GetTestFile(expectedFilename))
            .Returns(expectedTestFile);

            var expectedVariable = new List <VariableViewModel>(2);

            _testFileMapperMock
            .Setup(x => x.BuildVariableViewModel(expectedTestFile))
            .Returns(expectedVariable);

            // when
            var viewResult = _testController.Add(expectedFilename) as ViewResult;

            // then
            Assert.AreEqual("Edit", viewResult.ViewName);
            _testFileMapperMock.Verify(x => x.BuildVariableViewModel(It.IsAny <TestFile>()), Times.Once);

            var model = viewResult.Model as TestViewModel;

            Assert.That(model, Is.Not.Null);
            Assert.That(model.Filename, Is.EqualTo(expectedFilename));
            Assert.That(model.AvailableVariables, Is.EqualTo(expectedVariable));
            Assert.That(model.ExpectedHttpStatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(model.Method, Is.EqualTo(MethodType.GET));

            _testFileMapperMock.Verify(x => x.PopulateScriptSnippets(model), Times.Once);
        }
        public void Add_InvalidObject_ReturnsBadRequest()
        {
            //Act
            var result = _testController.Add(null).Result;

            //Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
        public void AddTestActionMethod()
        {
            TestController testController = new TestController();

            var response = testController.Add(4, 5) as ObjectResult;

            Assert.Equal(StatusCodes.Status200OK, response.StatusCode);
            Assert.Equal(9, response.Value);
        }