예제 #1
0
        public void Given_Valid_And_Different_Data_When_Execute_Diff_Then_Should_Return_Differences()
        {
            //Arrange
            var id            = _fixture.Create <string>();
            var base64String  = _fixture.Create <string>();
            var base64String2 = base64String.Replace(base64String.Substring(2, 1), base64String.Substring(4, 1));
            var differences   = _fixture.Build <Result>()
                                .With(x => x.AreEqual, false).With(x => x.AreSameSize, true)
                                .With(x => x.Differences, _fixture.CreateMany <Difference>().ToArray()).Create();

            var diffServiceMock = new Mock <IDiffService>();

            diffServiceMock.Setup(x => x.GetDifferences(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(differences);

            var comparisonServiceMock = new Mock <IComparisonService>();

            comparisonServiceMock.Setup(x => x.Get(It.IsNotNull <string>()))
            .Returns(new Comparison()
            {
                ComparisonId = id, Left = base64String, Right = base64String2
            })
            .Verifiable();

            var controller = new DiffController(diffServiceMock.Object, comparisonServiceMock.Object)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };


            //Act
            var response = controller.Diff(id);


            //Assert
            comparisonServiceMock.Verify(x => x.Get(It.IsNotNull <string>()), Times.Once);
            diffServiceMock.Verify(x => x.GetDifferences(It.IsNotNull <string>(), It.IsNotNull <string>()), Times.Once);
            Assert.NotNull(response);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Result retVal;

            Assert.IsTrue(response.TryGetContentValue(out retVal));
            Assert.IsTrue(!retVal.AreEqual);
            Assert.IsTrue(retVal.AreSameSize);
            CollectionAssert.AllItemsAreUnique(retVal.Differences);
            Assert.Greater(retVal.Differences.Count, 0);
        }
예제 #2
0
        public void Given_Valid_And_DiffSized_When_Execute_Diff_Then_Should_Return_AreDiffSize()
        {
            //Arrange
            var base64String = _fixture.Create <string>();
            var differences  = _fixture.Build <Result>()
                               .With(x => x.AreEqual, false).With(x => x.AreSameSize, false)
                               .With(x => x.Differences, new List <Difference>()).Create();

            var diffServiceMock = new Mock <IDiffService>();

            diffServiceMock.Setup(x => x.GetDifferences(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(differences);

            var repositoryMock = new Mock <IComparisonService>();

            repositoryMock.Setup(x => x.Get(It.IsNotNull <string>()))
            .Returns(new Comparison()
            {
                Left = base64String.Substring(0, base64String.Length - 2), Right = base64String
            })
            .Verifiable();

            var controller = new DiffController(diffServiceMock.Object, repositoryMock.Object)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

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

            //Act
            var response = controller.Diff(id);


            //Assert
            repositoryMock.Verify(x => x.Get(It.IsNotNull <string>()), Times.Once);
            diffServiceMock.Verify(x => x.GetDifferences(It.IsNotNull <string>(), It.IsNotNull <string>()), Times.Once);
            Assert.NotNull(response);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Result retVal;

            Assert.IsTrue(response.TryGetContentValue(out retVal));
            Assert.IsTrue(!retVal.AreEqual);
            Assert.IsTrue(!retVal.AreSameSize);
            CollectionAssert.IsEmpty(retVal.Differences);
        }
예제 #3
0
        public void Given_Id_Incomplete_Left_And_Right_Data_When_Execute_Diff_Then_Should_Return_Bad_Request()
        {
            //Arrange
            var id           = _fixture.Create <string>();
            var base64String = _fixture.Create <string>();

            var diffServiceMock = new Mock <IDiffService>();

            diffServiceMock.Setup(x => x.GetDifferences(It.IsAny <string>(), It.IsAny <string>()))
            .Verifiable();

            var comparisonServiceMock = new Mock <IComparisonService>();

            comparisonServiceMock.Setup(x => x.Get(It.IsNotNull <string>()))
            .Returns(new Comparison()
            {
                ComparisonId = id, Left = base64String, Right = ""
            })
            .Verifiable();

            var controller = new DiffController(diffServiceMock.Object, comparisonServiceMock.Object)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };


            //Act
            var response = controller.Diff(id);


            //Assert
            comparisonServiceMock.Verify(x => x.Get(It.IsNotNull <string>()), Times.Once);
            diffServiceMock.Verify(x => x.GetDifferences(It.IsNotNull <string>(), It.IsNotNull <string>()), Times.Never);
            Assert.NotNull(response);
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }