Beispiel #1
0
        public async Task Run_ReturnsTaskOnSuccess()
        {
            var handler   = new Mock <IQueryHandler <GetTaskQuery, TaskDTO> >();
            var container = new Container();
            var logger    = new Mock <ILogger>().Object;
            var listid    = Guid.NewGuid().ToString();
            var taskid    = Guid.NewGuid().ToString();
            var request   = new DefaultHttpRequest(new DefaultHttpContext());

            handler.Setup(h => h.Execute(It.IsAny <GetTaskQuery>()))
            .ReturnsAsync(new TaskDTO {
                Id = taskid, Name = "name", Description = "description"
            });
            container.RegisterInstance(handler.Object);
            container.RegisterInstance(_telemetryClient);
            GetTask.Container = container;

            var result = await GetTask.Run(request, listid, taskid, logger) as OkObjectResult;

            Assert.IsNotNull(result);

            var value = result.Value as TaskDTO;

            Assert.IsNotNull(value);

            Assert.AreEqual(taskid, value.Id);
            Assert.AreEqual("name", value.Name);
            Assert.AreEqual("description", value.Description);
        }
Beispiel #2
0
        public async Task Run_ReturnsErrorOnServerError()
        {
            var handler   = new Mock <IQueryHandler <GetTaskQuery, TaskDTO> >();
            var container = new Container();
            var logger    = new Mock <ILogger>().Object;
            var listid    = Guid.NewGuid().ToString();
            var taskid    = Guid.NewGuid().ToString();
            var request   = new DefaultHttpRequest(new DefaultHttpContext());

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

            var result = await GetTask.Run(request, listid, taskid, logger) as InternalServerErrorResult;

            Assert.IsNotNull(result);
        }