public void ShouldUpdateObjectWithProperStatus() { Random rnd = new Random(); var id = rnd.Next(); var mockProcessResultRepository = new Mock <IProcessResultRepository>(); mockProcessResultRepository .Setup(x => x.UpdateResultByContentId(It.IsAny <ProcessResult>(), It.IsAny <string>())) .Returns((ProcessResult processResult, string contentId) => { return(new ProcessResult { ProcessResultId = id, status = processResult.status, ContentId = contentId }); }); mockProcessResultRepository .Setup(x => x.GetResultByContentId(It.IsAny <string>())) .Returns((string contentId) => { return(new ProcessResult { ProcessResultId = id, ContentId = contentId }); }); var mockDiffenceSearchService = new Mock <IDiffenceSearchService>(); var comparisonService = new ComparisonService(mockProcessResultRepository.Object, mockDiffenceSearchService.Object); var comparisonResult = comparisonService.UpdateComparisonToProcessing("teste", StatusEnum.PROCESSED_FIRST); Assert.Equal(id, comparisonResult.ProcessResultId); Assert.Equal(StatusEnum.PROCESSED_FIRST, comparisonResult.status); Assert.Equal("teste", comparisonResult.ContentId); }
public void ShouldReturnObjectWithIdAndProperStatus() { Random rnd = new Random(); var id = rnd.Next(); var mockProcessResultRepository = new Mock <IProcessResultRepository>(); mockProcessResultRepository .Setup(x => x.SaveResult(It.IsAny <ProcessResult>())) .Returns((ProcessResult processResult) => { return(new ProcessResult { ProcessResultId = id, status = processResult.status, ContentId = processResult.ContentId }); }); var mockDiffenceSearchService = new Mock <IDiffenceSearchService>(); var comparisonService = new ComparisonService(mockProcessResultRepository.Object, mockDiffenceSearchService.Object); var comparisonResult = comparisonService.CreateNewComparison("teste"); Assert.Equal(id, comparisonResult.ProcessResultId); Assert.Equal(StatusEnum.NEW, comparisonResult.status); Assert.Equal("teste", comparisonResult.ContentId); }
public void ShouldUpdateObjectWithProperStatusAndCompareValues() { Random rnd = new Random(); var id = rnd.Next(); var mockComparisonRepository = new Mock <IProcessResultRepository>(); mockComparisonRepository .Setup(x => x.UpdateResultByContentId(It.IsAny <ProcessResult>(), It.IsAny <string>())) .Returns((ProcessResult processResult, string contentId) => processResult); mockComparisonRepository .Setup(x => x.GetResultByContentId(It.IsAny <string>())) .Returns((string contentId) => { return(new ProcessResult { ProcessResultId = id, ContentId = "teste" }); }); var itemToProcess = new ItemToProcess { Hash = "70A4B9F4707D258F559F91615297A3EC", Size = 200 }; var mockDiffenceSearchService = new Mock <IDiffenceSearchService>(); var comparisonService = new ComparisonService(mockComparisonRepository.Object, mockDiffenceSearchService.Object); var comparisonResult = comparisonService.SaveProcessResult(itemToProcess, itemToProcess); Assert.Equal(id, comparisonResult.ProcessResultId); Assert.Equal(StatusEnum.DONE, comparisonResult.status); Assert.Equal("teste", comparisonResult.ContentId); Assert.True(comparisonResult.IsEqual); Assert.True(comparisonResult.IsEqualSize); }
public void CompareProducts_Returns_Valid_Comparison_First_Basic_Product() { // Arrange var basicProduct = new BasicProduct(); var packagedProduct = new PackagedProduct(); var comparisonService = new ComparisonService(); var validConsumption = 3000; var expectedResultCount = 2; var expectedResult = new List <IProduct>() { basicProduct, packagedProduct }; comparisonService.Add(basicProduct); comparisonService.Add(packagedProduct); // Act var actualResult = comparisonService.CompareProducts(validConsumption); // Assert Assert.IsNotNull(actualResult); Assert.AreEqual(expectedResultCount, actualResult.Count()); Assert.IsTrue(actualResult.SequenceEqual(expectedResult)); }
public async Task ComparisonService_ComparisonAsync_Should_Return_Equal_True(byte[] valueLeft, byte[] valueRight, ComparisonEnum type) { ComparisonService comparisonService = new ComparisonService(_comparisonRepository.Object, _applicationDbContext.Object); await comparisonService.InsertOrUpdateAsync(new ComparisonInsertRequestDto() { Id = id, Value = valueLeft, ValueType = ComparisonEnum.Left }); await comparisonService.InsertOrUpdateAsync(new ComparisonInsertRequestDto() { Id = id, Value = valueRight, ValueType = ComparisonEnum.Right }); comparison.Should().NotBeNull(); ComparisonResponseDto result = await comparisonService.CompareAsync(new ComparisonRequestDto() { Id = id, ValueType = type }); ComparisonResponseObject resultObject = (ComparisonResponseObject)result.Result; resultObject.Equal.Should().BeFalse(); resultObject.SameSize.Should().BeTrue(); }
public async Task ComparisonService_Should_Update_ComparisonAsync(byte[] value, ComparisonEnum type) { ComparisonService comparisonService = new ComparisonService(_comparisonRepository.Object, _applicationDbContext.Object); await comparisonService.InsertOrUpdateAsync(new ComparisonInsertRequestDto() { Id = id, Value = value, ValueType = type }); byte[] newValue = new byte[4] { 1, 2, 3, 4 }; await comparisonService.InsertOrUpdateAsync(new ComparisonInsertRequestDto() { Id = id, Value = newValue, ValueType = type }); comparison.Should().NotBeNull(); if (type == ComparisonEnum.Left) { comparison.LeftArray.Should().Equal(newValue); } else { comparison.RightArray.Should().Equal(newValue); } }
public void Given_Invalid_Data_When_AddRight_Then_Should_Return_Exception() { //Arrange var id = _fixture.Create <string>(); var base64String = ""; var repoMock = new Mock <IComparisonRepository>(); repoMock.Setup(x => x.Get(It.IsNotNull <string>())) .Returns((Comparison)null) .Verifiable(); repoMock.Setup(x => x.Insert(It.IsAny <Comparison>())) .Verifiable(); repoMock.Setup(x => x.Update(It.IsAny <Comparison>())) .Verifiable(); var service = new ComparisonService(repoMock.Object); //Act & Assert Assert.Throws <ArgumentNullException>(() => service.AddRight(id, base64String)); repoMock.Verify(x => x.Insert(It.IsNotNull <Comparison>()), Times.Never); repoMock.Verify(x => x.Get(It.IsNotNull <string>()), Times.Never); repoMock.Verify(x => x.Update(It.IsNotNull <Comparison>()), Times.Never); }
public void Given_Valid_Id_When_Execute_Get_Then_Should_Return_Comparison() { //Arrange var id = _fixture.Create <string>(); var base64String = _fixture.Create <string>().Base64Encode(); var comparison = new Comparison() { ComparisonId = id, Left = base64String, Right = base64String }; var repoMock = new Mock <IComparisonRepository>(); repoMock.Setup(x => x.Get(It.IsNotNull <string>())) .Returns(comparison) .Verifiable(); var service = new ComparisonService(repoMock.Object); //Act var result = service.Get(id); //Assert repoMock.Verify(x => x.Get(It.IsNotNull <string>()), Times.Once); Assert.IsNotNull(result); Assert.AreEqual(comparison.ComparisonId, result.ComparisonId); Assert.AreEqual(comparison.Left, result.Left); Assert.AreEqual(comparison.Right, result.Right); }
public void Initialize() { var mock = new Mock <IRepository>(); _products = new[] { new TariffProductModel { Name = PName1, AnnualCost = 60, ConsumptionCost = 0.22m, ConsumptionThreshold = 0 }, new TariffProductModel { Name = PName2, AnnualCost = 800, ConsumptionCost = 0.3m, ConsumptionThreshold = 4000 } }; mock.Setup(p => p.GetAllTariffs()).Returns(_products.ToList()); _service = new ComparisonService(mock.Object); }
public void Given_New_Valid_Data_When_AddRight_Then_Should_Save_Or_Update() { //Arrange var id = _fixture.Create <string>(); var base64String = _fixture.Create <string>().Base64Encode(); var repoMock = new Mock <IComparisonRepository>(); repoMock.Setup(x => x.Get(It.IsNotNull <string>())) .Returns((Comparison)null) .Verifiable(); repoMock.Setup(x => x.Insert(It.IsAny <Comparison>())) .Verifiable(); repoMock.Setup(x => x.Update(It.IsAny <Comparison>())) .Verifiable(); var service = new ComparisonService(repoMock.Object); //Act service.AddRight(id, base64String); //Assert //Update must not be execute repoMock.Verify(x => x.Update(It.IsNotNull <Comparison>()), Times.Never); repoMock.Verify(x => x.Get(It.IsNotNull <string>()), Times.Once); repoMock.Verify(x => x.Insert(It.IsNotNull <Comparison>()), Times.Once); }
//展开节点事件 private void TreeViewItem_Expanded(object sender, RoutedEventArgs e) { selectedItem = sender as TreeViewItem; DirNode dirNode = selectedItem.DataContext as DirNode; bool needUpdate = ComparisonService.BuiledNodeChildren(dirNode); if (needUpdate) { selectedItem.ItemsSource = dirNode.Children; } }
public ViewResult Index() { ComparisonService service = new ComparisonService((ComparisonWidgetSettings)this.HttpContext.Application["cws"]); service.SourceFileName(Server.MapPath("~/App_Data/" + sourceFileName)); service.TargetFileName(Server.MapPath("~/App_Data/" + targetFileName)); service.ResultFileName(Server.MapPath("~/App_Data/" + redlineFileName)); Groupdocs.Comparison.Common.ChangeInfo[] all_changes = service.Compare(); return(View(all_changes)); }
public async Task ComparisonService_Comparison_ShouldThrow_Exception_Due_To_Null_Comparison_Value() { ComparisonService comparisonService = new ComparisonService(_comparisonRepository.Object, _applicationDbContext.Object); BusinessException ex = await Assert.ThrowsAsync <BusinessException>(async() => { await comparisonService.CompareAsync(new ComparisonRequestDto() { Id = 1, ValueType = ComparisonEnum.Left }); }); ex.Message.Should().Equals("No record found!"); }
//绑定事件选择数据 private void Page_Loaded(object sender, RoutedEventArgs e) { int index = oldIncident.SelectedIndex; oldIncident.ItemsSource = ComparisonService.GetComboBoxResource(); oldIncident.SelectedIndex = index == -1 ? 0 : index; index = newIncident.SelectedIndex; newIncident.ItemsSource = ComparisonService.GetComboBoxResource(); newIncident.SelectedIndex = index == -1 ? 0 : index; //添加标签标注缓存 TagSupport.CheckTagSort(); }
//选中文件夹的事件 private void DirTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { locationTextBlock.Visibility = Visibility.Visible; AddTag.Visibility = Visibility.Visible; compareTable.Visibility = Visibility.Visible; ComparisonInfo info = ComparisonService.GetInfoByNode(dirTree.SelectedItem as DirNode); // 放入两个事件的创建时间 info.OldTime = (oldIncident.SelectedItem as IncidentBean).CreateTimeFormat; info.NewTime = (newIncident.SelectedItem as IncidentBean).CreateTimeFormat; comparisonGrid.DataContext = info; }
//为所选目录添加标签 private void AddTag_Click(object sender, RoutedEventArgs e) { if (!(dirTree.SelectedItem is DirNode dirNode)) { MessageBox.Show("未选中文件夹", "提示", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } ComparisonService.AllOrEditTag(dirNode.Path, dirNode.Tag.Id == 0); //刷新页面数据 ComparisonService.RefreshNode(ref dirNode); TreeViewItem_Expanded(selectedItem, null); }
public async Task GenerateBenchmarkListWithSimpleComparisonAsyncShouldExpandTheUrbanRuralIfNotEnoughSchoolsFound() { var mockFinancialDataService = new Mock <IFinancialDataService>(); var testResult = new SchoolTrustFinancialDataObject(); testResult.URN = 321; testResult.SchoolName = "test"; testResult.FinanceType = "Academies"; testResult.UrbanRural = "Town and fringe"; Task <List <SchoolTrustFinancialDataObject> > task = Task.Run(() => { return(new List <SchoolTrustFinancialDataObject> { testResult }); }); mockFinancialDataService.Setup(m => m.SearchSchoolsByCriteriaAsync(It.IsAny <BenchmarkCriteria>(), It.IsAny <EstablishmentType>(), false, true)) .Returns((BenchmarkCriteria criteria, EstablishmentType estType, bool excludePartial, bool excludeFeds) => task); var mockContextDataService = new Mock <IContextDataService>(); var mockBenchmarkCriteriaBuilderService = new Mock <IBenchmarkCriteriaBuilderService>(); mockBenchmarkCriteriaBuilderService.Setup(s => s.BuildFromSimpleComparisonCriteria(It.IsAny <FinancialDataModel>(), It.IsAny <SimpleCriteria>(), It.IsAny <int>())) .Returns((FinancialDataModel dm, SimpleCriteria sc, int percentage) => new BenchmarkCriteria() { Gender = new[] { "Male" } }); mockBenchmarkCriteriaBuilderService.Setup(s => s.BuildFromSimpleComparisonCriteriaExtended(It.IsAny <FinancialDataModel>(), It.IsAny <SimpleCriteria>(), It.IsAny <int>())) .Returns((FinancialDataModel dm, SimpleCriteria sc, int percentage) => new BenchmarkCriteria() { Gender = new[] { "Male" } }); var service = new ComparisonService(mockFinancialDataService.Object, mockBenchmarkCriteriaBuilderService.Object); var comparisonResult = await service.GenerateBenchmarkListWithSimpleComparisonAsync(new BenchmarkCriteria() { Gender = new [] { "Male" } }, EstablishmentType.Maintained, 15, new SimpleCriteria(), new FinancialDataModel("123", "14-15", testResult, EstablishmentType.Maintained)); mockFinancialDataService.Verify(s => s.SearchSchoolsByCriteriaAsync(It.IsAny <BenchmarkCriteria>(), EstablishmentType.Maintained, false, true), Times.AtLeast(11)); Assert.AreEqual(5, comparisonResult.BenchmarkCriteria.UrbanRural.Length); Assert.IsTrue(comparisonResult.BenchmarkCriteria.UrbanRural.Contains("Rural and village")); Assert.IsTrue(comparisonResult.BenchmarkCriteria.UrbanRural.Contains("Town and fringe")); Assert.IsTrue(comparisonResult.BenchmarkCriteria.UrbanRural.Contains("Urban and city")); Assert.IsTrue(comparisonResult.BenchmarkCriteria.UrbanRural.Contains("Hamlet and isolated dwelling")); Assert.IsTrue(comparisonResult.BenchmarkCriteria.UrbanRural.Contains("Conurbation")); }
public void CompareProducts_Throws_Argument_Exception_Less_Then_Zero() { // Arrange var basicProduct = new BasicProduct(); var packagedProduct = new PackagedProduct(); var comparisonService = new ComparisonService(); var inValidConsumption = -1; comparisonService.Add(basicProduct); comparisonService.Add(packagedProduct); // Act var actualResult = comparisonService.CompareProducts(inValidConsumption); }
public void Add_Should_Add_Product() { // Arrange var comparisonService = new ComparisonService(); var product = new BasicProduct(); // Act try { comparisonService.Add(product); } catch (Exception ex) { Assert.Fail($"Throwed an exception during adding process. Exception message: {ex.Message}"); } }
public async Task GenerateBenchmarkListWithBestInClassComparisonAsyncShouldNotExpandWhenNotEnoughSchoolsFound() { var testResult = new SchoolTrustFinancialDataObject(); testResult.URN = 321; testResult.SchoolName = "test"; testResult.FinanceType = "Maintained"; testResult.UrbanRural = "Town and fringe"; testResult.RevenueReserve = 10; testResult.TotalIncome = 100; Task <List <SchoolTrustFinancialDataObject> > task = Task.Run(() => { var results = new List <SchoolTrustFinancialDataObject>(); for (var i = 0; i < 51; i++) { results.Add(testResult); } return(results); }); var mockFinancialDataService = new Mock <IFinancialDataService>(); mockFinancialDataService.Setup(m => m.SearchSchoolsByCriteriaAsync(It.IsAny <BenchmarkCriteria>(), It.IsAny <EstablishmentType>(), true, true)) .Returns((BenchmarkCriteria criteria, EstablishmentType estType, bool excludePartial, bool excludeFeds) => task); var mockBenchmarkCriteriaBuilderService = new Mock <IBenchmarkCriteriaBuilderService>(); mockBenchmarkCriteriaBuilderService.Setup(s => s.BuildFromBicComparisonCriteria(It.IsAny <FinancialDataModel>(), It.IsAny <BestInClassCriteria>(), It.IsAny <int>())) .Returns((FinancialDataModel dm, BestInClassCriteria bic, int percentage) => new BenchmarkCriteria() { Gender = new[] { "Male" } }); var service = new ComparisonService(mockFinancialDataService.Object, mockBenchmarkCriteriaBuilderService.Object); var comparisonResult = await service.GenerateBenchmarkListWithBestInClassComparisonAsync(EstablishmentType.Maintained, new BenchmarkCriteria() { Gender = new[] { "Male" } }, new BestInClassCriteria(), new FinancialDataModel("123", "14-15", testResult, EstablishmentType.Maintained)); mockFinancialDataService.Verify(s => s.SearchSchoolsByCriteriaAsync(It.IsAny <BenchmarkCriteria>(), EstablishmentType.Maintained, true, true), Times.Exactly(1)); Assert.AreEqual(15, comparisonResult.BenchmarkSchools.Count); }
public void Given_Invalid_Id_When_Execute_Get_Then_Should_Return_Exception() { //Arrange var id = ""; var repoMock = new Mock <IComparisonRepository>(); repoMock.Setup(x => x.Get(It.IsNotNull <string>())) .Returns((Comparison)null) .Verifiable(); var service = new ComparisonService(repoMock.Object); //Act & Assert Assert.Throws <ArgumentNullException>(() => service.Get(id)); repoMock.Verify(x => x.Get(It.IsNotNull <string>()), Times.Never); }
public async Task GenerateBenchmarkListWithSimpleComparisonAsyncShouldExpandTheUrbanRuralIfNotEnoughSchoolsFound() { var mockFinancialDataService = new Mock <IFinancialDataService>(); var testResult = new Document(); testResult.SetPropertyValue("URN", "321"); testResult.SetPropertyValue("School Name", "test"); testResult.SetPropertyValue("FinanceType", "A"); testResult.SetPropertyValue("UrbanRuralInner", "Town and fringe"); Task <List <Document> > task = Task.Run(() => { return(new List <Document> { testResult }); }); mockFinancialDataService.Setup(m => m.SearchSchoolsByCriteriaAsync(It.IsAny <BenchmarkCriteria>(), It.IsAny <EstablishmentType>())) .Returns((BenchmarkCriteria criteria, EstablishmentType estType) => task); var mockBenchmarkCriteriaBuilderService = new Mock <IBenchmarkCriteriaBuilderService>(); mockBenchmarkCriteriaBuilderService.Setup(s => s.BuildFromSimpleComparisonCriteria(It.IsAny <SchoolFinancialDataModel>(), It.IsAny <SimpleCriteria>(), It.IsAny <int>())) .Returns((SchoolFinancialDataModel dm, SimpleCriteria sc, int percentage) => new BenchmarkCriteria() { Gender = new[] { "Male" } }); var service = new ComparisonService(mockFinancialDataService.Object, mockBenchmarkCriteriaBuilderService.Object); var comparisonResult = await service.GenerateBenchmarkListWithSimpleComparisonAsync(new BenchmarkCriteria() { Gender = new [] { "Male" } }, EstablishmentType.Maintained, 15, new SimpleCriteria(), new SchoolFinancialDataModel("123", "14-15", testResult, SchoolFinancialType.Maintained)); mockFinancialDataService.Verify(s => s.SearchSchoolsByCriteriaAsync(It.IsAny <BenchmarkCriteria>(), EstablishmentType.Maintained), Times.AtLeast(11)); Assert.AreEqual(5, comparisonResult.BenchmarkCriteria.UrbanRural.Length); Assert.IsTrue(comparisonResult.BenchmarkCriteria.UrbanRural.Contains("Rural and village")); Assert.IsTrue(comparisonResult.BenchmarkCriteria.UrbanRural.Contains("Town and fringe")); Assert.IsTrue(comparisonResult.BenchmarkCriteria.UrbanRural.Contains("Urban and city")); Assert.IsTrue(comparisonResult.BenchmarkCriteria.UrbanRural.Contains("Hamlet and isolated dwelling")); Assert.IsTrue(comparisonResult.BenchmarkCriteria.UrbanRural.Contains("Conurbation")); }
public void Print_Should_Not_Throw_Exception() { // Arrange var basicProduct = new BasicProduct(); var packagedProduct = new PackagedProduct(); var comparisonService = new ComparisonService(); comparisonService.Add(basicProduct); comparisonService.Add(packagedProduct); // Act try { comparisonService.PrintProducts(); } catch (Exception ex) { Assert.Fail($"Print function has thrown an exception. Exception message: {ex.Message}"); } }
static void Main(string[] args) { var productComparer = new ComparisonService(); productComparer.Add(new BasicProduct()); productComparer.Add(new PackagedProduct()); // Task test data productComparer.CompareProducts(2000); productComparer.PrintProducts(); productComparer.CompareProducts(3500); productComparer.PrintProducts(); productComparer.CompareProducts(4500); productComparer.PrintProducts(); productComparer.CompareProducts(6000); productComparer.PrintProducts(); }
public async Task ComparisonService_Left_Comparison_Should_Throw_Exception_Due_To_Null_Left_Value() { ComparisonService comparisonService = new ComparisonService(_comparisonRepository.Object, _applicationDbContext.Object); byte[] value = new byte[4] { 1, 2, 3, 4 }; await comparisonService.InsertOrUpdateAsync(new ComparisonInsertRequestDto() { Id = id, Value = value, ValueType = ComparisonEnum.Right }); BusinessException ex = await Assert.ThrowsAsync <BusinessException>(async() => { await comparisonService.CompareAsync(new ComparisonRequestDto() { Id = 1, ValueType = ComparisonEnum.Right }); }); ex.Message.Should().Equals("Left array is null!"); }
//实现选择框的选中事件 private void Incident_SelectionChanged(object sender, SelectionChangedEventArgs e) { //在页面刚加载的时候,设置selectedIndex会触发这里的事件,回导致bean为null if (!(newIncident.SelectedItem is IncidentBean bean)) { return; } uint newIncidentId = bean.Id; bean = oldIncident.SelectedItem as IncidentBean; if (bean == null) { return; } uint oldIncidentId = bean.Id; if (oldIncidentId == 0 || newIncidentId == 0) { return; } dirTree.ItemsSource = ComparisonService.GetRootNodes(oldIncidentId, newIncidentId); }
public async Task ComparisonService_ComparisonAsync_Should_Return_Equal_False(byte[] valueLeft, byte[] valueRight, ComparisonEnum type) { ComparisonService comparisonService = new ComparisonService(_comparisonRepository.Object, _applicationDbContext.Object); await comparisonService.InsertOrUpdateAsync(new ComparisonInsertRequestDto() { Id = id, Value = valueLeft, ValueType = ComparisonEnum.Left }); await comparisonService.InsertOrUpdateAsync(new ComparisonInsertRequestDto() { Id = id, Value = valueRight, ValueType = ComparisonEnum.Right }); comparison.Should().NotBeNull(); ComparisonResponseDto result = await comparisonService.CompareAsync(new ComparisonRequestDto() { Id = id, ValueType = type }); ComparisonResponseObject resultObject = (ComparisonResponseObject)result.Result; resultObject.Equal.Should().BeFalse(); resultObject.SameSize.Should().BeTrue(); resultObject.Difference.Length.Should().Be(2); var diffList = resultObject.Difference.OffSets.ToList(); if (type == ComparisonEnum.Left) { diffList[0].OffSet.Should().Be(0); diffList[1].OffSet.Should().Be(3); } else { diffList[0].OffSet.Should().Be(2); diffList[1].OffSet.Should().Be(3); } }
public CompareController(ComparisonService comparisonService) { _comparisonService = comparisonService; }
private async Task CompareSubmissions(Assignment assignment, string user, ComparisonService comparisonService, string accessToken) { var client = new HttpClient(); client.BaseAddress = new Uri(comparisonService.BaseUrl); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "Bearer", accessToken); var payload = new Model.ComparisonRequest { Title = assignment.Title, Submissions = new List <Model.Submission>() }; foreach (var submission in assignment.Submissions) { var curSubmission = await this.submissionManager.GetSubmissionByIdAsync(submission.Id, user); var reqSubmission = new Model.Submission { FirstName = submission.FirstName, LastName = submission.LastName, Files = new List <TokenizedFile>() }; foreach (var file in curSubmission.Files) { var reqFile = new TokenizedFile { FileName = file.FileName, Tokens = new List <int>() }; var tokenList = JsonConvert.DeserializeObject <List <TokenWithPosition> >(file.TokenizedContent); reqFile.Tokens = tokenList.Select(t => t.Token).ToList(); reqSubmission.Files.Add(reqFile); } payload.Submissions.Add(reqSubmission); } var response = await client.PostAsJsonAsync(comparisonService.RequestPath, payload); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var comparatorResults = await response.Content.ReadAsAsync <List <ComparatorResult> >(); var entityResults = new List <Result>(); foreach (var comparatorResult in comparatorResults) { var firstSubmission = assignment.Submissions.FirstOrDefault( s => s.FirstName.Equals(comparatorResult.First.FirstName) && s.LastName.Equals(comparatorResult.First.LastName)); var secondSubmission = assignment.Submissions.FirstOrDefault( s => s.FirstName.Equals(comparatorResult.Second.FirstName) && s.LastName.Equals(comparatorResult.Second.LastName)); var entityResult = new Result { AssignmentId = assignment.Id, FirstId = firstSubmission.Id, SecondId = secondSubmission.Id, Matches = new List <Match>() }; foreach (var match in comparatorResult.Matches) { entityResult.Matches.Add(new Match { Result = entityResult, PatternIndex = match.PatternIndex, TextIndex = match.TextIndex, TokenLength = match.Length }); } entityResults.Add(entityResult); } await this.assignmentManager.SaveComparisonResultsAsync(assignment.Id, user, entityResults); await this.assignmentManager.SetEvaluationStateAsync(assignment.Id, user, AssignmentState.Evaluated); } else { await this.assignmentManager.SetEvaluationStateAsync(assignment.Id, user, AssignmentState.Open); } }