public void When_SettingLeftWithNullModel_Should_ReturnBadRequest()
        {
            var serviceMock = new Mock<IDataComparisonService>(MockBehavior.Strict);
            var controller = new DiffController(serviceMock.Object);
            var result = controller.SetLeft(null);

            Assert.IsType<BadRequestResult>(result);
        }
        public void When_SettingRightWithInvalidBase64Characters_Should_ReturnBadRequest()
        {
            var dataComparisonService = new DataComparisonService(new InMemoryDataComparisonRepository());
            var controller = new DiffController(dataComparisonService);

            var result = controller.SetRight(new SetDataModel { Data = "WRONG BASE64 DATA" });
            Assert.IsType<BadRequestErrorMessageResult>(result);
        }
        public void When_SettingLeftWithDataContainingInvalidBase64Characters_Should_ReturnBadRequest()
        {
            var serviceMock = new Mock<IDataComparisonService>(MockBehavior.Strict);
            var controller = new DiffController(serviceMock.Object);
            var result = controller.SetLeft(new SetDataModel { Data = "tes!" }) as BadRequestErrorMessageResult;

            Assert.NotNull(result);
            Assert.Equal("Invalid base-64 string.", result.Message);
        }
        public void When_SettingRightWithNullData_Should_ReturnOk()
        {
            var serviceMock = new Mock<IDataComparisonService>(MockBehavior.Strict);
            serviceMock.Setup(x => x.SetRight(It.IsAny<byte[]>())).Verifiable();
            var controller = new DiffController(serviceMock.Object);

            var result = controller.SetRight(new SetDataModel { Data = null });

            Assert.IsType<OkResult>(result);
            serviceMock.VerifyAll();
        }
        public void When_GettingDiff_Should_ReturnResultFromDataComparisonService()
        {
            var expectedResult = new ComparisonResult(ComparisonState.Equal);
            var serviceMock = new Mock<IDataComparisonService>(MockBehavior.Strict);
            serviceMock.Setup(x => x.Compare()).Returns(expectedResult).Verifiable();
            var controller = new DiffController(serviceMock.Object);

            var result = controller.GetDiff();

            Assert.Equal(expectedResult, result);
            serviceMock.VerifyAll();
        }
        public void When_Comparing_And_RightEqualsLeft_Should_ReturnEqualState()
        {
            var dataComparisonService = new DataComparisonService(new InMemoryDataComparisonRepository());
            var controller = new DiffController(dataComparisonService);

            var result = controller.SetLeft(new SetDataModel { Data = CreateDataFromUnicodeString("test data") });
            Assert.IsType<OkResult>(result);

            result = controller.SetRight(new SetDataModel { Data = CreateDataFromUnicodeString("test data") });
            Assert.IsType<OkResult>(result);

            var compResult = controller.GetDiff();
            Assert.Equal(ComparisonState.Equal, compResult.ComparisonState);
        }
        public void When_SettingLeft_And_RightWithDifferentSizeData_Should_ReturnNoDifferences()
        {
            var dataComparisonService = new DataComparisonService(new InMemoryDataComparisonRepository());
            var controller = new DiffController(dataComparisonService);

            var result = controller.SetLeft(new SetDataModel { Data = CreateDataFromUnicodeString("333") });
            Assert.IsType<OkResult>(result);

            result = controller.SetRight(new SetDataModel { Data = CreateDataFromUnicodeString("4444") });
            Assert.IsType<OkResult>(result);

            var compResult = controller.GetDiff();
            Assert.Null(compResult.Differences);
        }
        public void When_GettingDifferences_Should_ReturnDifferences()
        {
            var dataComparisonService = new DataComparisonService(new InMemoryDataComparisonRepository());
            var controller = new DiffController(dataComparisonService);

            var left = CreateDataFromBytes(new byte[] { 1, 1, 0, 0, 1, 0, 1, 1, 1, 1 });
            var result = controller.SetLeft(new SetDataModel { Data = left });
            Assert.IsType<OkResult>(result);

            var right = CreateDataFromBytes(new byte[] { 1, 1, 0, 1, 0, 1, 0, 1, 0, 1 });
            result = controller.SetRight(new SetDataModel { Data = right });
            Assert.IsType<OkResult>(result);

            var compResult = controller.GetDiff();

            Assert.Equal(ComparisonState.DifferentContent, compResult.ComparisonState);
            Assert.Equal(2, compResult.Differences.Count);

            var diff1 = compResult.Differences.ElementAt(0);
            Assert.Equal(3, diff1.Offset);
            Assert.Equal(4, diff1.Length);

            var diff2 = compResult.Differences.ElementAt(1);
            Assert.Equal(8, diff2.Offset);
            Assert.Equal(1, diff2.Length);
        }
        public void When_ResettingData_Should_ReturnOk()
        {
            var serviceMock = new Mock<IDataComparisonService>(MockBehavior.Strict);
            serviceMock.Setup(x => x.Reset()).Verifiable();
            var controller = new DiffController(serviceMock.Object);
            var result = controller.ResetValues();

            Assert.IsType<OkResult>(result);
            serviceMock.VerifyAll();
        }
        public void When_SettingRightWithDataWithInvalidPadding_Should_ReturnBadRequest()
        {
            var serviceMock = new Mock<IDataComparisonService>(MockBehavior.Strict);
            var controller = new DiffController(serviceMock.Object);
            var result = controller.SetRight(new SetDataModel { Data = "TEST1" }) as BadRequestErrorMessageResult;

            Assert.NotNull(result);
            Assert.Equal("Invalid base-64 string.", result.Message);
        }