Пример #1
0
        public void TestDemo()
        {
            var controller = new DemoController();
            var res        = controller.Get(1);

            Assert.AreEqual("value", res);
        }
        public void Get_should_return_anonymous()
        {
            var controller = new DemoController
            {
                User = new ClaimsPrincipal()
            };

            var response = controller.Get();

            response.Should().Be(@"The user is: anonymous");
        }
        public void Get_should_return_maurice()
        {
            var controller = new DemoController
            {
                User = new ClaimsPrincipal(
                    new ClaimsIdentity(new[]
                {
                    new Claim(ClaimTypes.Name, "Maurice")
                }))
            };

            var response = controller.Get();

            response.Should().Be(@"The user is: Maurice");
        }
Пример #4
0
        public void Get_Return_Status()
        {
            //Arrange
            Mock <IDemoRepository> mock = new Mock <IDemoRepository>();

            mock.Setup(x => x.Get()).Returns("Hello World");
            DemoController democontroller = new DemoController(mock.Object);

            democontroller.Request       = new HttpRequestMessage();
            democontroller.Configuration = new HttpConfiguration();

            // Act
            HttpResponseMessage value = democontroller.Get();

            //Assert
            Assert.IsNotNull(value);
            Assert.IsNotNull(value.Content);
        }
Пример #5
0
        public void Call_Get_Method()
        {
            //Arrange
            Mock <IDemoRepository> mock = new Mock <IDemoRepository>();

            mock.Setup(x => x.Get()).Returns("Hello World");

            DemoController democontroller = new DemoController(mock.Object);

            democontroller.Request       = new HttpRequestMessage();
            democontroller.Configuration = new HttpConfiguration();
            //Act
            var response = democontroller.Get();
            //assert
            string result;

            Assert.IsTrue(response.TryGetContentValue <string>(out result));
            Assert.AreEqual("Hello World", result);
        }
Пример #6
0
        public void Check_Link_Address()
        {
            //arrange
            Mock <IDemoRepository> mock = new Mock <IDemoRepository>();

            mock.Setup(x => x.Get()).Returns("Hello World");
            DemoController democontroller = new DemoController(mock.Object);

            democontroller.Request = new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost:56980/api/Demo")
            };
            democontroller.Configuration = new HttpConfiguration();
            democontroller.Configuration.Routes.MapHttpRoute(name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional });

            democontroller.RequestContext.RouteData = new HttpRouteData(route: new HttpRoute(), values: new HttpRouteValueDictionary {
                { "controller", "Demo" }
            });
            //Act
            var response = democontroller.Get();

            //Assert
            Assert.AreEqual("http://localhost:56980/api/Demo", response.RequestMessage.RequestUri.AbsoluteUri);
        }