public void GetDiff_Should_return_ContentDoNotMatch_When_left_and_right_are_same_size_but_different_in_content() { // Arrange var fakeRepository = new Mock <IDiffRepository>(); fakeRepository .Setup(x => x.GetDiff(It.IsAny <int>())) .Returns(new DiffDto() { Left = "VGhpcyBpcyB0aGUgdGVzdA==", Right = "VGhpc19pcyBUSEUgdGVzdA==" }); var sut = new DiffService(fakeRepository.Object); // Act var result = sut.GetDiff(1); // Assert result.GetStrProperty(DiffMessages.DiffResultTypeProperty).Should().Be(DiffMessages.ContentDoNotMatchResponse); ((List <DiffSection>)result.GetProperty(DiffMessages.DiffsProperty)).Count.Should().Be(2); ((List <DiffSection>)result.GetProperty(DiffMessages.DiffsProperty))[0].Offset.Should().Be(4); ((List <DiffSection>)result.GetProperty(DiffMessages.DiffsProperty))[0].Length.Should().Be(1); ((List <DiffSection>)result.GetProperty(DiffMessages.DiffsProperty))[1].Offset.Should().Be(8); ((List <DiffSection>)result.GetProperty(DiffMessages.DiffsProperty))[1].Length.Should().Be(3); }
public IHttpActionResult Diff(int id) { DiffService diff = new DiffService(); var response = diff.Compare(id); return(Ok(response)); }
public DiffServiceTests() { _cache = Substitute.For <ICache>(); _mapper = Substitute.For <IMapper>(); _sut = new DiffService(_cache, _mapper); }
public void Setup() { controller = new DiffController(); leftRepository = new LeftRepository(); rightRepository = new RightRepository(); diffService = new DiffService(); }
public DiffServiceTestsFixture() { _autoFixture = new Fixture(); _diffService = new DiffService(); InitialItem = null; UpdatedItem = null; }
/// <summary> /// Gets the controller. /// </summary> /// <returns>The controller instance.</returns> private FileDiffController GetController() { var retrieveService = new RetrieveService(this.context); var uploadService = new UploadService(this.context); var diffService = new DiffService(this.context); return(new FileDiffController(diffService, retrieveService, uploadService)); }
public DiffServiceTests() { _mockEntryRepository = new Mock <IEntryRepository>(); _mockEntryValidator = new Mock <IEntryValidator>(); _mockBase64Validator = new Mock <IBase64Validator>(); _mockDiffCalculator = new Mock <IDiffCalculator>(); _objectToTest = new DiffService(_mockEntryRepository.Object, _mockEntryValidator.Object, _mockBase64Validator.Object, _mockDiffCalculator.Object); }
// GET: DiffMvc public ActionResult List() { var diffService = new DiffService(_diffRepository); var diffList = diffService.GetDiffs().ToList(); //_diffRepository.GetDiffs().ToList() return(View(diffList)); }
/// <summary> /// Dependency Injection Container used for decoupling (testability etc.) /// </summary> /// <param name="diffRepository">Constructor injected repository.</param> public DiffController(IDiffRepository diffRepository) { if (diffRepository == null) { throw new ArgumentNullException(nameof(diffRepository)); } _diffRepository = diffRepository; _diffService = new DiffService(_diffRepository); _modelFactory = new ModelFactory(); }
public async Task DiffReturnsEmptyList() { var gitService = Substitute.For <IGitService>(); gitService.CompareWith(null, null, null, null, null).ReturnsNull(); var target = new DiffService(gitService); var result = await target.Diff(null, null, null, null, null); Assert.That(result, Is.Empty); }
public void Left_Should_return_true_When_data_is_Base64_string() { // Arrange var fakeRepository = new Mock <IDiffRepository>(); fakeRepository .Setup(x => x.UpsertDiff(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>())); var sut = new DiffService(fakeRepository.Object); // Act var result = sut.Left(1, "VGhpcyBpcyBhIHRlc3Qu"); // Assert result.Should().BeTrue(); }
public void Right_Should_return_false_When_data_is_Base64_string() { // Arrange var fakeRepository = new Mock <IDiffRepository>(); fakeRepository .Setup(x => x.UpsertDiff(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>())); var sut = new DiffService(fakeRepository.Object); // Act var result = sut.Right(1, "=NotBase64="); // Assert result.Should().BeFalse(); }
public static void ExecuteServiceWithoutCommandReturnInconclusiveMessage() { //Arrange var settings = new Settings { Messages = new MessageSettings { Inconclusive = "Inconclusive" } }; IOptions <Settings> options = Options.Create(settings); var service = new DiffService(options, new List <IDiffCommand>()); //Act var result = service.GetDiff(new List <DataEntity>()); //Assert Assert.Equal("Inconclusive", result.Message.Trim()); }
public DiffController GetMockedDiffController(Json json) { var jsonId = "99"; var mockRepository = new Mock <IJsonRepository>(); mockRepository.Setup(x => x.GetById(jsonId)).Returns(Task.FromResult(json)); mockRepository.Setup(x => x.AddOrUpdate(It.IsAny <Json>())); mockRepository.Setup(x => x.SaveChanges()); var diffService = new DiffService(); var encodeService = new EncodeService(); var logger = new Logger <DiffController>(new LoggerFactory()); var controller = new DiffController(mockRepository.Object, diffService, encodeService, logger); return(controller); }
public void GetDiff_Should_return_Equals_When_left_and_right_are_equals() { // Arrange var fakeRepository = new Mock <IDiffRepository>(); fakeRepository .Setup(x => x.GetDiff(It.IsAny <int>())) .Returns(new DiffDto() { Left = "VGhpcyBpcyBhIHVuaXQgdGVzdA==", Right = "VGhpcyBpcyBhIHVuaXQgdGVzdA==" }); var sut = new DiffService(fakeRepository.Object); // Act var result = sut.GetDiff(1).GetStrProperty(DiffMessages.DiffResultTypeProperty); // Assert result.Should().Be(DiffMessages.EqualsResponse); }
public async Task IdenticalSizesIdenticalContent_Compare_ReturnEquals() { // Arrange var leftFile = Convert.FromBase64String(TestConstants.File1Base64Content); var rightFile = Convert.FromBase64String(TestConstants.File1Base64Content); const int id = 1; var mockContext = await Task.Run(() => GetMockContext(id, leftFile, rightFile)); var diffService = new DiffService(mockContext.Object); // Act var result = await diffService.GetDiffAsync(id); // Assert Assert.IsNotNull(result, "The comparison result of the files is null!"); Assert.AreEqual(ComparisonResult.Equals.ToString(), result.DiffResultType, "The result type should be Equals!"); Assert.IsNull(result.Diffs, "The list of differences should be null!"); }
public void GetDiff_Should_return_SizeDoNotMatch_When_left_and_right_are_different_in_size() { // Arrange var fakeRepository = new Mock <IDiffRepository>(); fakeRepository .Setup(x => x.GetDiff(It.IsAny <int>())) .Returns(new DiffDto() { Left = "VGhpcyBpcyBhIHVuaXQgdGVzdA==", Right = "U2l6ZURvTm90TWF0Y2g=" }); var sut = new DiffService(fakeRepository.Object); // Act var result = sut.GetDiff(1).GetStrProperty(DiffMessages.DiffResultTypeProperty); // Assert result.Should().Be(DiffMessages.SizeDoNotMatchResponse); }
public void ShouldParsePr960() { var target = new DiffService(Substitute.For <IGitClient>()); var result = DiffUtilities.ParseFragment(Properties.Resources.pr_960_diff).ToList(); Assert.That(4, Is.EqualTo(result.Count)); Assert.That(11, Is.EqualTo(result[0].OldLineNumber)); Assert.That(11, Is.EqualTo(result[0].NewLineNumber)); Assert.That(24, Is.EqualTo(result[0].Lines.Count)); Assert.That(61, Is.EqualTo(result[1].OldLineNumber)); Assert.That(61, Is.EqualTo(result[1].NewLineNumber)); Assert.That(21, Is.EqualTo(result[1].Lines.Count)); Assert.That(244, Is.EqualTo(result[2].OldLineNumber)); Assert.That(247, Is.EqualTo(result[2].NewLineNumber)); Assert.That(15, Is.EqualTo(result[2].Lines.Count)); Assert.That(268, Is.EqualTo(result[3].OldLineNumber)); Assert.That(264, Is.EqualTo(result[3].NewLineNumber)); Assert.That(15, Is.EqualTo(result[3].Lines.Count)); // - public class UsageTracker : IUsageTracker Assert.That(17, Is.EqualTo(result[0].Lines[7].OldLineNumber)); Assert.That(-1, Is.EqualTo(result[0].Lines[7].NewLineNumber)); Assert.That(8, Is.EqualTo(result[0].Lines[7].DiffLineNumber)); // + public sealed class UsageTracker : IUsageTracker, IDisposable Assert.That(-1, Is.EqualTo(result[0].Lines[8].OldLineNumber)); Assert.That(18, Is.EqualTo(result[0].Lines[8].NewLineNumber)); Assert.That(9, Is.EqualTo(result[0].Lines[8].DiffLineNumber)); // IConnectionManager connectionManager; Assert.That(26, Is.EqualTo(result[0].Lines[17].OldLineNumber)); Assert.That(25, Is.EqualTo(result[0].Lines[17].NewLineNumber)); Assert.That(18, Is.EqualTo(result[0].Lines[17].DiffLineNumber)); }
public async Task IdenticalSizesNonIdenticalContent_Compare_ReturnContentDiff() { // Arrange var leftFile = Convert.FromBase64String(TestConstants.File1Base64Content); var rightFile = Convert.FromBase64String(TestConstants.FileIdenticalSizeNonIdenticalContentBase64Content); const int id = 1; var mockContext = await Task.Run(() => GetMockContext(id, leftFile, rightFile)); var diffService = new DiffService(mockContext.Object); var expectedDiff = new List <DifferenceDTO>() { new DifferenceDTO() { Offset = 0, Length = 1 }, new DifferenceDTO() { Offset = 2, Length = 2 } }; // Act var result = await diffService.GetDiffAsync(id); // Assert Assert.IsNotNull(result, "The comparison result of the files is null!"); Assert.AreEqual(ComparisonResult.ContentDoNotMatch.ToString(), result.DiffResultType, "The result type should be ContentDoNotMatch!"); Assert.IsNotNull(result.Diffs, "The list of differences is null!"); CollectionAssert.AreEqual(expectedDiff, result.Diffs, new DifferenceDTOComparer(), "The list of diffs is not matching with the expected result!"); }
public async Task RightFileNull_Compare_ThrowException() { // Arrange var leftFile = Convert.FromBase64String(TestConstants.File1Base64Content); const int id = 1; var mockContext = await Task.Run(() => GetMockContext(id, leftFile, null)); var diffService = new DiffService(mockContext.Object); // Act var exceptionThrown = false; try { await diffService.GetDiffAsync(id); } catch (ArgumentNullException) { exceptionThrown = true; } // Assert Assert.IsTrue(exceptionThrown, "ArgumentNullException was not thrown!"); }
public DiffServiceTest() { _service = new DiffService(); }
/// <summary> /// Initializes a new instance of the <see cref="DiffServiceTests"/> class. /// </summary> public DiffServiceTests() { _differenceRepository = Substitute.For <IDifferenceRepository>(); _dataItemRepository = Substitute.For <IDataItemRepository>(); _service = new DiffService(_differenceRepository, _dataItemRepository); }
public void SetUp() { _repositoryMock = new Mock <IDiffContentRepository>(MockBehavior.Strict); _service = new DiffService(_repositoryMock.Object); }
public DiffServiceTest() { // Arrange service = new DiffService(); }
public DiffResult DiffTest(string left, string right) { var diffService = new DiffService(); return(diffService.SimpleDiff(left, right)); }
public DiffServiceTest() { comparisonRepositoryMock = new Mock <IDiffRepository>(); target = new DiffService(comparisonRepositoryMock.Object); }
public void StartUp() { _diffService = new DiffService(new DiffResultRepository(new InMemoryRepository())); }