public async Task Setup() { MessageBinding bindingModel = new MessageBinding(); bindingModel.Payload = "ZG9jdG9yV2hv"; //doctorWho await DifferencesClient.LeftTask(basePath, 1, 5, bindingModel); }
public void DifferencesRight_AreNotEqual_ReturnComparisonResult() { MessageBinding bindingModel = new MessageBinding(); bindingModel.Payload = "ZG9jdG9yU3RyYW5nZQ=="; //doctorStrange ComparisonResult result = DifferencesClient.RightTask(basePath, 1, 57, bindingModel).Result; Assert.AreEqual(result.AreEqual, ComparisonResultEnum.NotEqual); }
public void DifferencesRight_AreEqualWithDifferentPayload_ReturnComparisonResult() { MessageBinding bindingModel = new MessageBinding(); bindingModel.Payload = "ZG9jdG9yV2hp"; //doctorWhi ComparisonResult result = DifferencesClient.RightTask(basePath, 1, 57, bindingModel).Result; Assert.AreEqual(result.AreEqual, ComparisonResultEnum.Equal); Assert.AreEqual(result.Offsets, new int[] { 8 }); Assert.AreEqual(result.OffsetsLength, 1); }
public IActionResult Common(int id, MessageBinding model, string method) { _logger.LogDebug(string.Format("({0}-id:{1},model:{2})", method, id, JsonConvert.SerializeObject(model, Formatting.Indented))); if (id > 0 && model != null && !string.IsNullOrEmpty(model.Payload) && Methods.IsValidBase64(model.Payload)) { using (var db = new DatabaseContext()) { List <Message> messages = db.Messages.Where(i => i.MessageId == id).ToList(); if (messages.Count > 0) { Message dbMessage = messages[messages.Count - 1]; // _logger.LogDebug(string.Format("{0}", JsonConvert.SerializeObject(dbMessage, Formatting.Indented))); // byte[] Base64ToByteArrayOfDatabase = Methods.DecodeBase64ToByteArray(dbMessage.Payload); byte[] Base64ToByteArrayOfModel = Methods.DecodeBase64ToByteArray(model.Payload); ComparisonResult res = BitsDiff.CompareByteArrays(Base64ToByteArrayOfDatabase, Base64ToByteArrayOfModel); string middleEndpointUrl = Configuration["EndPoints:middle"]; int v = Convert.ToInt32(HttpContext.GetRequestedApiVersion().ToString()); _logger.LogDebug(string.Format("({0})", middleEndpointUrl)); var resultFromMiddleEndPoint = DifferencesClient.Middle(middleEndpointUrl, v, id, res).Result; _logger.LogDebug(string.Format("({0} id:{1},message:{2})", method, id, JsonConvert.SerializeObject(resultFromMiddleEndPoint, Formatting.Indented))); return(Ok(resultFromMiddleEndPoint)); } else { try { Message message = new Message() { MessageId = id, Payload = model.Payload }; db.Messages.Add(message); db.SaveChanges(); _logger.LogDebug(string.Format( "({0}:{1}, Message with ID: {2} does not exist and added to the database.", method, message, id)); return(Ok()); } catch (Exception e) { _logger.LogError(string.Format("({0}:{1})", method, e)); return(BadRequest()); } } } } _logger.LogDebug(string.Format("({0}:BadRequest)", method)); return(BadRequest()); }