コード例 #1
0
        public async System.Threading.Tasks.Task PostProblemNoForm()
        {
            // Arrange
            this._projectService = new ProjectSpeedy.Tests.ServicesTests.ProjectData();
            this._problemService = new ProjectSpeedy.Tests.ServicesTests.ProblemData();
            this._controller     = new ProjectSpeedy.Controllers.ProblemController(this._logger.Object, this._problemService, this._projectService);

            // Act
            var test = await this._controller.PostAsync(null, "ProjectId", "ProblemId");

            // Assert
            var result = test as BadRequestResult;

            Assert.AreEqual(400, result.StatusCode);
        }
コード例 #2
0
        public async System.Threading.Tasks.Task GetExceptionHttpOther()
        {
            // Arrange
            this._projectService = new ProjectSpeedy.Tests.ServicesTests.ProjectData();
            this._problemService = new ProjectSpeedy.Tests.ServicesTests.ProblemDataNotFoundOther();
            this._controller     = new ProjectSpeedy.Controllers.ProblemController(this._logger.Object, this._problemService, this._projectService);

            // Act
            var test = await this._controller.GetAsync("ProblemId", "ProjectId");

            // Assert
            // Taken from https://stackoverflow.com/questions/51489111/how-to-unit-test-with-actionresultt
            var result = test.Result as ObjectResult;

            Assert.IsNull(test.Value);
            Assert.AreEqual(500, result.StatusCode);
        }
コード例 #3
0
        public async System.Threading.Tasks.Task PutExceptionHttpOther()
        {
            this._projectService = new ProjectSpeedy.Tests.ServicesTests.ProjectData();
            this._problemService = new ProjectSpeedy.Tests.ServicesTests.ProblemDataNotFoundOther();
            this._controller     = new ProjectSpeedy.Controllers.ProblemController(this._logger.Object, this._problemService, this._projectService);

            // Act
            var test = await this._controller.PutAsync(new ProjectSpeedy.Models.Problem.ProblemNew()
            {
                Name = "Name"
            }, "ProjectId");

            // Assert
            var result = test as ObjectResult;

            Assert.AreEqual(500, result.StatusCode);
        }
コード例 #4
0
        public async System.Threading.Tasks.Task PostProblemDuplicateName()
        {
            // Arrange
            this._projectService = new ProjectSpeedy.Tests.ServicesTests.ProjectData();
            this._problemService = new ProjectSpeedy.Tests.ServicesTests.ProblemData();
            this._controller     = new ProjectSpeedy.Controllers.ProblemController(this._logger.Object, this._problemService, this._projectService);

            // Act
            var test = await this._controller.PostAsync(new ProjectSpeedy.Models.Problem.ProblemUpdate()
            {
                Name = "Problem Name",
            }, "ProjectId", "ProblemIdDif");

            // Assert
            var result = test as ObjectResult;

            Assert.AreEqual(400, result.StatusCode);
        }
コード例 #5
0
        public async System.Threading.Tasks.Task PutNoCreate()
        {
            // Throws an error when calling the view
            this._projectService = new ProjectSpeedy.Tests.ServicesTests.ProjectData();
            this._problemService = new ProjectSpeedy.Tests.ServicesTests.ProblemDataNoCreate();
            this._controller     = new ProjectSpeedy.Controllers.ProblemController(this._logger.Object, this._problemService, this._projectService);

            // Act
            var test = await this._controller.PutAsync(new ProjectSpeedy.Models.Problem.ProblemNew()
            {
                Name = "Problem"
            }, "ProjectId");

            // Assert
            var result = test as ObjectResult;

            Assert.AreEqual(500, result.StatusCode);
        }
コード例 #6
0
        public async System.Threading.Tasks.Task PostProblemHttpExceptionOther()
        {
            // Arrange
            this._projectService = new ProjectSpeedy.Tests.ServicesTests.ProjectData();
            this._problemService = new ProjectSpeedy.Tests.ServicesTests.ProblemDataNotFoundOther();
            this._controller     = new ProjectSpeedy.Controllers.ProblemController(this._logger.Object, this._problemService, this._projectService);

            // Act
            var test = await this._controller.PostAsync(new ProjectSpeedy.Models.Problem.ProblemUpdate()
            {
                Name        = "Name",
                Description = "Desc"
            }, "ProjectId", "ProblemId");

            // Assert
            var result = test as ObjectResult;

            Assert.AreEqual(500, result.StatusCode);
        }
コード例 #7
0
        public async System.Threading.Tasks.Task GetInvalidIds()
        {
            using (var stream = new MemoryStream())
            {
                using (var streamBets = new MemoryStream())
                {
                    // Arrange
                    this._projectService = new ProjectSpeedy.Tests.ServicesTests.ProjectData();
                    this._problemService = new ProjectSpeedy.Tests.ServicesTests.ProblemData();
                    this._controller     = new ProjectSpeedy.Controllers.ProblemController(this._logger.Object, this._problemService, this._projectService);

                    // Act
                    var test = await this._controller.GetAsync("ProjectIdOther", "ProblemId");

                    // Assert
                    var result = test.Result as NotFoundResult;
                    Assert.IsNull(test.Value);
                    Assert.AreEqual(404, result.StatusCode);
                }
            }
        }
コード例 #8
0
        public async System.Threading.Tasks.Task Get()
        {
            using (var stream = new MemoryStream())
            {
                using (var streamBets = new MemoryStream())
                {
                    // Arrange
                    this._projectService = new ProjectSpeedy.Tests.ServicesTests.ProjectData();
                    this._problemService = new ProjectSpeedy.Tests.ServicesTests.ProblemData();
                    this._controller     = new ProjectSpeedy.Controllers.ProblemController(this._logger.Object, this._problemService, this._projectService);

                    // Act
                    var test = await this._controller.GetAsync("ProjectId", "ProblemId");

                    // Assert
                    var result = test.Result as OkObjectResult;
                    Assert.IsNull(test.Value);
                    Assert.AreEqual(200, result.StatusCode);
                    Assert.AreEqual("Problem Name", ((ProjectSpeedy.Models.Problem.Problem)result.Value).Name);
                }
            }
        }