public void ReturnLengthNotEqual() { // Arrange var leftInput = Convert.FromBase64String(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("some data"))); var rightInput = Convert.FromBase64String(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("some other data"))); Guid id = Guid.NewGuid(); using (var differenceContext = new DifferenceContext(this.contextOptions)) { Difference diff = new Difference { Id = id, Left = leftInput, Right = rightInput }; differenceContext.Differences.Add(diff); differenceContext.SaveChanges(); } // Act var comparisonResult = this.diffService.GetDifferencesAsync(id).Result; // Assert Assert.Equal(DiffComparisonResultType.LengthNotEqual, comparisonResult.Result); }
public void ReturnDifferences() { // Arrange var leftInput = Convert.FromBase64String(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("LF data"))); var rightInput = Convert.FromBase64String(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("RT data"))); Guid id = Guid.NewGuid(); using (var differenceContext = new DifferenceContext(this.contextOptions)) { Difference diff = new Difference { Id = id, Left = leftInput, Right = rightInput }; differenceContext.Differences.Add(diff); differenceContext.SaveChanges(); } // Act var comparisonResult = this.diffService.GetDifferencesAsync(id).Result; // Assert Assert.Equal(DiffComparisonResultType.NotEqual, comparisonResult.Result); Assert.Single(comparisonResult.Differences); Assert.Collection(comparisonResult.Differences, pair => Assert.True(pair.Key == 0 && pair.Value == 2)); }
public async void UpdateTheDiffDataOfAnExistingResource(string left, string right) { // Arrange var leftInput = Convert.FromBase64String(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("LF data"))); var rightInput = Convert.FromBase64String(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("RT data"))); Guid id = Guid.NewGuid(); using (var differenceContext = new DifferenceContext(this.contextOptions)) { Difference diff = new Difference { Id = id, Left = leftInput, Right = rightInput }; differenceContext.Differences.Add(diff); differenceContext.SaveChanges(); } // Act var newLeftInput = left == null ? null : Convert.FromBase64String( Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(left))); var newRightInput = right == null ? null : Convert.FromBase64String( Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(right))); var diffToUpdate = new DifferenceForUpdateDto { Left = newLeftInput, Right = newRightInput }; await this.diffService.UpdateAsync(id, diffToUpdate); // Assert Difference difference; using (var differenceContext = new DifferenceContext(this.contextOptions)) { difference = differenceContext.Differences.Find(id); } Assert.NotEqual( "LF data", System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(Convert.ToBase64String(difference.Left)))); Assert.NotEqual( "RT data", System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(Convert.ToBase64String(difference.Right)))); }
public async void UpdateTheRightDiffDataGivenAnExistingId() { // Arrange var rightInput = Convert.FromBase64String(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("Right data"))); Guid id = Guid.NewGuid(); using (var differenceContext = new DifferenceContext(this.contextOptions)) { Difference diff = new Difference { Id = id, Right = rightInput }; differenceContext.Differences.Add(diff); differenceContext.SaveChanges(); } // Act var newRightInput = Convert.FromBase64String(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("New right data"))); await this.diffService.AddRightDiffItemAsync(id, newRightInput); // Assert // Assert Difference difference; using (var differenceContext = new DifferenceContext(this.contextOptions)) { difference = differenceContext.Differences.Find(id); } Assert.NotNull(difference); Assert.Equal( "New right data", System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(Convert.ToBase64String(difference.Right)))); }