コード例 #1
0
        public async Task Run_ReturnsServerErrorOnServerError()
        {
            var handler   = new Mock <ICommandHander <CreateTaskCommand, string> >();
            var container = new Container();
            var task      = new TaskDTO();
            var listId    = Guid.NewGuid().ToString();

            handler.Setup(h => h.Execute(It.IsAny <CreateTaskCommand>()))
            .ThrowsAsync(new Exception());
            container.RegisterInstance(handler.Object);
            container.RegisterInstance(_telemetryClient);
            CreateTask.Container = container;

            var result = await CreateTask.Run(task, listId) as InternalServerErrorResult;

            Assert.IsNotNull(result);
        }
コード例 #2
0
        public async Task Run_ReturnsUriOnSuccess()
        {
            Environment.SetEnvironmentVariable("TASK_RESOURCE_URI", "https://www.test.co.uk/{0}/task/{1}");

            var handler   = new Mock <ICommandHander <CreateTaskCommand, string> >();
            var container = new Container();
            var task      = new TaskDTO();
            var listId    = Guid.NewGuid().ToString();
            var taskid    = Guid.NewGuid().ToString();
            var expected  = new Uri($"https://www.test.co.uk/{listId}/task/{taskid}");

            handler.Setup(h => h.Execute(It.IsAny <CreateTaskCommand>())).ReturnsAsync(taskid);
            container.RegisterInstance(handler.Object);
            container.RegisterInstance(_telemetryClient);
            CreateTask.Container = container;

            var result = await CreateTask.Run(task, listId) as CreatedResult;

            Assert.IsNotNull(result);

            Assert.IsNull(result.Value);
            Assert.AreEqual(expected, result.Location);
        }