コード例 #1
0
        public void GetDefaultDesctiption_ForMvc_Test()
        {
            //Arange
            var resultExecutedContext = new ResultExecutedContext
            {
                Controller = new PrompterController()
            };

            resultExecutedContext.Controller
                .ControllerContext = new ActionExecutedContext
            {
                Controller = new PrompterController()
            };

            HttpContext.Current = new HttpContext(
                new HttpRequest(null,
                    "http://testUrl/test",
                    null),
                new HttpResponse(null));

            var webContexts = new WebContexts(HttpContext.Current, resultExecutedContext);

            var defaultUserActivityDesctiption = new DefaultUserActivityDescription();

            //Act
            var actual = defaultUserActivityDesctiption
                .GetDefaultDescription(webContexts);
            
            //Assert
            Assert.That(actual != null);
            Assert.That(actual.Contains("/test"));
            Assert.That(actual.Contains("PrompterController"));
            Assert.That(actual.Contains("Mvc"));
            Assert.That(actual.Contains("GET"));

            Assert.Throws<ArgumentNullException>(() =>
            {
                defaultUserActivityDesctiption
                    .GetDefaultDescription(null);
            });
        }
コード例 #2
0
        public void GetDefaultDesctiption_ForWebApi_Test()
        {
            //Arange
            var dummyUserService = new Mock<IUserService>();
            var dummyUserMapper = new Mock<IUserMapper>();
            

            var actionExecutedContext = new HttpActionExecutedContext
            {
                ActionContext = new HttpActionContext()
            };

            actionExecutedContext.ActionContext
                .ControllerContext = new HttpControllerContext
                {
                    Controller = new WebApplication.WebApi.PrompterController(
                        dummyUserService.Object,
                        dummyUserMapper.Object)
                };

            HttpContext.Current = new HttpContext(
                new HttpRequest(null,
                    "http://testUrl/test",
                    null),
                new HttpResponse(null));

            var webContexts = new WebContexts(HttpContext.Current, actionExecutedContext);

            var defaultUserActivityDesctiption = new DefaultUserActivityDescription();

            //Act
            var actual = defaultUserActivityDesctiption
                .GetDefaultDescription(webContexts);

            //Assert
            Assert.That(actual != null);
            Assert.That(actual.Contains("/test"));
            Assert.That(actual.Contains("PrompterController"));
            Assert.That(actual.Contains("WebApi"));
            Assert.That(actual.Contains("GET"));

            Assert.Throws<ArgumentNullException>(() =>
            {
                defaultUserActivityDesctiption
                    .GetDefaultDescription(null);
            });
        }