Beispiel #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);
        }
Beispiel #2
0
        public async System.Threading.Tasks.Task PutNoForm()
        {
            // Arrange
            this._betService     = new ProjectSpeedy.Tests.ServicesTests.Bet();
            this._problemService = new ProjectSpeedy.Tests.ServicesTests.ProblemData();
            this._controller     = new ProjectSpeedy.Controllers.BetController(this._logger.Object, this._betService, this._problemService);

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

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

            Assert.AreEqual(400, result.StatusCode);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #8
0
        public async System.Threading.Tasks.Task PutException()
        {
            // Arrange
            this._betService     = new ProjectSpeedy.Tests.ServicesTests.BetDataNoCreate();
            this._problemService = new ProjectSpeedy.Tests.ServicesTests.ProblemDataException();
            this._controller     = new ProjectSpeedy.Controllers.BetController(this._logger.Object, this._betService, this._problemService);

            // Act
            ActionResult test = await this._controller.PutAsync("ProjectId", "ProblemId", new ProjectSpeedy.Models.Bet.BetNew()
            {
                Name = "New Bet Name"
            });

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

            Assert.AreEqual(500, result.StatusCode);
        }
Beispiel #9
0
        public async System.Threading.Tasks.Task PutBadProblemId()
        {
            using (var stream = new MemoryStream())
            {
                using (var streamBets = new MemoryStream())
                {
                    // Arrange
                    this._problemServices    = new ProjectSpeedy.Tests.ServicesTests.ProblemDataNotFound();
                    this._betFeedbackService = new ProjectSpeedy.Tests.ServicesTests.BetFeedbackData();
                    this._controller         = new ProjectSpeedy.Controllers.BetFeedbackController(this._logger.Object, this._betFeedbackService, this._problemServices);

                    // Act
                    var test = await this._controller.PutAsync("ProjectId", "ProblemId", "BetId", new ProjectSpeedy.Models.BetFeedback.BetFeedbackNewUpdate());

                    // Assert
                    var result = test as NotFoundResult;
                    Assert.AreEqual(404, result.StatusCode);
                }
            }
        }
Beispiel #10
0
        public async System.Threading.Tasks.Task PutNoForm()
        {
            using (var stream = new MemoryStream())
            {
                using (var streamBets = new MemoryStream())
                {
                    // Arrange
                    this._problemServices   = new ProjectSpeedy.Tests.ServicesTests.ProblemData();
                    this._betCommentService = new ProjectSpeedy.Tests.ServicesTests.BetCommentData();
                    this._controller        = new ProjectSpeedy.Controllers.BetCommentController(this._logger.Object, this._problemServices, this._betCommentService);

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

                    // Assert
                    var result = test as BadRequestResult;
                    Assert.AreEqual(400, result.StatusCode);
                }
            }
        }
Beispiel #11
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);
                }
            }
        }
Beispiel #12
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);
                }
            }
        }
Beispiel #13
0
        public async System.Threading.Tasks.Task PutExceptionService()
        {
            using (var stream = new MemoryStream())
            {
                using (var streamBets = new MemoryStream())
                {
                    // Arrange
                    this._problemServices   = new ProjectSpeedy.Tests.ServicesTests.ProblemDataException();
                    this._betCommentService = new ProjectSpeedy.Tests.ServicesTests.BetCommentDataNoCreate();
                    this._controller        = new ProjectSpeedy.Controllers.BetCommentController(this._logger.Object, this._problemServices, this._betCommentService);

                    // Act
                    var test = await this._controller.PutAsync("ProjectId", "ProblemId", "BetId", new ProjectSpeedy.Models.BetComment.BetCommentNewUpdate()
                    {
                        Comment = "Test comment"
                    });

                    // Assert
                    var result = test as ObjectResult;
                    Assert.AreEqual(500, result.StatusCode);
                }
            }
        }
Beispiel #14
0
 public BetFeedbackController(ILogger <BetFeedbackController> logger, ProjectSpeedy.Services.IBetFeedback iBetFeedback, ProjectSpeedy.Services.IProblem problemServices)
 {
     this._logger          = logger;
     this._betFeedback     = iBetFeedback;
     this._problemServices = problemServices;
 }
Beispiel #15
0
 /// <summary>
 /// All bet comment related actions.
 /// </summary>
 /// <param name="logger">Used to log any errors which occur in this controller.</param>
 /// <param name="problemServices">Allows us to interact with problems.</param>
 /// <param name="betCommentService">Allows us to interact with bet comments.</param>
 public BetCommentController(ILogger <BetCommentController> logger, ProjectSpeedy.Services.IProblem problemServices, ProjectSpeedy.Services.IBetComment betCommentService)
 {
     this._logger            = logger;
     this._problemServices   = problemServices;
     this._betCommentService = betCommentService;
 }
Beispiel #16
0
 /// <summary>
 /// All problem related actions.
 /// </summary>
 /// <param name="logger">Used to log any errors which occur in this controller.</param>
 /// <param name="problemServices">Allows us to interact with problems.</param>
 /// <param name="projectServices">Allows us to interact with projects.</param>
 public ProblemController(ILogger <ProblemController> logger, ProjectSpeedy.Services.IProblem problemServices, ProjectSpeedy.Services.IProject projectServices)
 {
     this._logger          = logger;
     this._problemServices = problemServices;
     this._projectService  = projectServices;
 }