コード例 #1
0
        public void Right_InvalidInput_ReturnBadRequest()
        {
            //Arrange
            var encodedData = "not_a_json".Base64Encode();

            //Act
            var response = _diffController.Right(encodedData) as ObjectResult;

            //Assert
            Assert.Equal((int)HttpStatusCode.BadRequest, response.StatusCode);
            _sessionPersistenceServiceMock.Verify(m => m.Save(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
        }
コード例 #2
0
        public async Task ShouldSaveMessageToSessionRightSide()
        {
            Guid sessionId = Guid.NewGuid();

            ISessionRepository repository = Substitute.For <ISessionRepository>();

            repository.Get(sessionId.ToString()).Returns(new SessionBuilder(sessionId.ToString()).Build());

            DiffController controller = new DiffController(repository);

            ActionResult result = await controller.Right(sessionId, new WebApi.Models.Message()
            {
                Data = ApplicationConstants.DefaultData
            });

            result.ShouldBeAssignableTo <OkObjectResult>();
        }
コード例 #3
0
ファイル: DiffControllerTests.cs プロジェクト: semefi/DiffAPI
        public void Given_Invalid_ID_When_Execute_Right_Then_Should_Return_Bad_Request()
        {
            //Arrange
            var diffServiceMock   = new Mock <IDiffService>();
            var comparisonService = new Mock <IComparisonService>();

            comparisonService.Setup(x => x.AddRight(It.IsNotNull <string>(), It.IsNotNull <string>()))
            .Throws(new ArgumentNullException("data"))
            .Verifiable();
            var controller = new DiffController(diffServiceMock.Object, comparisonService.Object)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            var id           = "";
            var base64String = _fixture.Create <string>();

            //Act & Assert
            Assert.Throws <ArgumentNullException>(() => controller.Right(id, base64String));
            comparisonService.Verify(x => x.AddRight(It.IsNotNull <string>(), It.IsNotNull <string>()), Times.Once);
        }
コード例 #4
0
ファイル: DiffControllerTests.cs プロジェクト: semefi/DiffAPI
        public void Given_Valid_Data_When_Execute_Right_Then_Should_Return_Ok()
        {
            //Arrange
            var diffServiceMock   = new Mock <IDiffService>();
            var comparisonService = new Mock <IComparisonService>();

            comparisonService.Setup(x => x.AddRight(It.IsNotNull <string>(), It.IsNotNull <string>())).Verifiable();
            var controller = new DiffController(diffServiceMock.Object, comparisonService.Object)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            var id           = _fixture.Create <string>();
            var base64String = _fixture.Create <string>();

            //Act
            var response = controller.Right(id, base64String);

            //Assert
            comparisonService.Verify(x => x.AddRight(It.IsNotNull <string>(), It.IsNotNull <string>()), Times.Once);
            Assert.NotNull(response);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }