public void CreatedByDefault() { SimpleDataWebServiceClient webServiceClient = Create(); InMemoryRecord record = ProductionRecords.NewRecord().MarkAsNew(); SubmitDataRequest request = new SubmitDataRequest { Credentials = CreateCredentials(), SubmitDataRecords = new[] { record.ConvertToSubmitDataRecord() } }; DateTime before = DateTime.Now.AddSeconds(-10).ToUniversalTime(); DateTime after = before.AddSeconds(+20); SubmitDataResponse response = webServiceClient.SubmitData(request); Assert.That(response, Is.Not.Null); Assert.That(DatabaseRecords.Count, Is.EqualTo(1)); InMemoryRecord inserted = DatabaseRecords[0]; Assert.That(inserted.GetFieldValue("CreatedBy", "null"), Is.EqualTo("User")); Assert.That(inserted.GetFieldValue("CreatedDateTime", DateTime.MinValue), Is.InRange(before, after)); }
public void CreatedBySetInRequest() { SimpleDataWebServiceClient webServiceClient = Create(); InMemoryRecord record = ProductionRecords.NewRecord().MarkAsNew(); record.SetFieldValue("CreatedBy", "UnitTests"); record.SetFieldValue("CreatedDateTime", DateTime.Today); SubmitDataRequest request = new SubmitDataRequest { Credentials = CreateCredentials(), SubmitDataRecords = new[] { record.ConvertToSubmitDataRecord() } }; SubmitDataResponse response = webServiceClient.SubmitData(request); Assert.That(response, Is.Not.Null); Assert.That(DatabaseRecords.Count, Is.EqualTo(1)); InMemoryRecord inserted = DatabaseRecords[0]; Assert.That(inserted.GetFieldValue("CreatedBy", "null"), Is.EqualTo("UnitTests")); Assert.That(inserted.GetFieldValue("CreatedDateTime", DateTime.MinValue), Is.EqualTo(DateTime.Today.ToUniversalTime())); }
public dynamic Save(object model) { IDynamicAmplaViewProperties amplaViewProperties = viewProperties; amplaViewProperties.Enforce.CanAdd(); SubmitDataRequest request = new SubmitDataRequest { Credentials = CreateCredentials() }; List <SubmitDataRecord> records = new List <SubmitDataRecord>(); List <object> models = new List <object> { model.ToExpando() }; IAmplaBinding binding = new AmplaAddDataDynamicBinding(models, records, amplaViewProperties, modelProperties); if (binding.Validate() && binding.Bind()) { request.SubmitDataRecords = records.ToArray(); SubmitDataResponse response = webServiceClient.SubmitData(request); IAmplaBinding resultBinding = new AmplaDataSubmissionResultDynamicBinding(response.DataSubmissionResults, models); if (resultBinding.Validate()) { resultBinding.Bind(); } } return(models[0]); }
/// <summary> /// Adds the specified model. /// </summary> /// <param name="model">The model.</param> public void Add(TModel model) { IAmplaViewProperties <TModel> amplaViewProperties = GetViewProperties(model); amplaViewProperties.Enforce.CanAdd(); SubmitDataRequest request = new SubmitDataRequest { Credentials = CreateCredentials() }; List <SubmitDataRecord> records = new List <SubmitDataRecord>(); List <TModel> models = new List <TModel> { model }; IAmplaBinding binding = new AmplaAddDataBinding <TModel>(models, records, amplaViewProperties, ModelProperties); if (binding.Validate() && binding.Bind()) { request.SubmitDataRecords = records.ToArray(); SubmitDataResponse response = WebServiceClient.SubmitData(request); IAmplaBinding resultBinding = new AmplaDataSubmissionResultBinding <TModel>(response.DataSubmissionResults, models, ModelProperties); if (resultBinding.Validate()) { resultBinding.Bind(); } } }
public void Update() { SimpleDataWebServiceClient webServiceClient = Create(); InMemoryRecord record = ProductionRecords.NewRecord().MarkAsNew(); InMemoryRecord update = record.Clone(); update.Fields.Clear(); update.Location = record.Location; update.Fields.Add(new FieldValue("New Field", "100")); SubmitDataRequest request = new SubmitDataRequest { Credentials = CreateCredentials(), SubmitDataRecords = new[] { record.ConvertToSubmitDataRecord() } }; SubmitDataResponse response = webServiceClient.SubmitData(request); Assert.That(response.DataSubmissionResults, Is.Not.Null); Assert.That(response.DataSubmissionResults.Length, Is.EqualTo(1)); Assert.That(response.DataSubmissionResults[0].RecordAction, Is.EqualTo(RecordAction.Insert)); Assert.That(response.DataSubmissionResults[0].SetId, Is.GreaterThan(100)); Assert.That(DatabaseRecords.Count, Is.EqualTo(1)); Assert.That(DatabaseRecords[0].Find("New Field"), Is.Null); update.RecordId = (int)response.DataSubmissionResults[0].SetId; request = new SubmitDataRequest { Credentials = CreateCredentials(), SubmitDataRecords = new[] { update.ConvertToSubmitDataRecord() } }; response = webServiceClient.SubmitData(request); Assert.That(response.DataSubmissionResults, Is.Not.Null); Assert.That(response.DataSubmissionResults.Length, Is.EqualTo(1)); Assert.That(response.DataSubmissionResults[0].RecordAction, Is.EqualTo(RecordAction.Update)); Assert.That(response.DataSubmissionResults[0].SetId, Is.EqualTo(update.RecordId)); Assert.That(DatabaseRecords.Count, Is.EqualTo(1)); Assert.That(DatabaseRecords[0].Find("New Field"), Is.Not.Null); Assert.That(DatabaseRecords[0].Find("New Field").Value, Is.EqualTo("100")); }
public void GetDataReturnsLocation() { SimpleDataWebServiceClient webServiceClient = new SimpleDataWebServiceClient( database, configuration, new SimpleSecurityWebServiceClient("User")); InMemoryRecord record = ProductionRecords.NewRecord().MarkAsNew(); SubmitDataRequest submitRequest = new SubmitDataRequest { Credentials = CreateCredentials(), SubmitDataRecords = new[] { record.ConvertToSubmitDataRecord() } }; SubmitDataResponse submitResponse = webServiceClient.SubmitData(submitRequest); Assert.That(submitResponse.DataSubmissionResults, Is.Not.Null); Assert.That(submitResponse.DataSubmissionResults.Length, Is.EqualTo(1)); Assert.That(submitResponse.DataSubmissionResults[0].RecordAction, Is.EqualTo(RecordAction.Insert)); Assert.That(submitResponse.DataSubmissionResults[0].SetId, Is.GreaterThan(100)); string recordId = Convert.ToString(submitResponse.DataSubmissionResults[0].SetId); Assert.That(DatabaseRecords.Count, Is.EqualTo(1)); Assert.That(DatabaseRecords[0].Location, Is.EqualTo(location)); GetDataRequest request = new GetDataRequest { Credentials = CreateCredentials(), Filter = new DataFilter { Location = record.Location, Criteria = new[] { new FilterEntry { Name = "Id", Value = recordId } } }, View = new GetDataView { Context = NavigationContext.Plant, Mode = NavigationMode.Location, Module = AmplaModules.Production }, Metadata = true, OutputOptions = new GetDataOutputOptions { ResolveIdentifiers = false }, }; GetDataResponse response = webServiceClient.GetData(request); AssertResponseContainsValue(response, "Duration", "90"); AssertResponseContainsValue(response, "Location", location); }
protected int UpdateRecord(InMemoryRecord record) { SubmitDataRequest request = new SubmitDataRequest { Credentials = new Credentials { Username = "******", Password = "******" }, SubmitDataRecords = new[] { record.ConvertToSubmitDataRecord() } }; SubmitDataResponse response = webServiceClient.SubmitData(request); Assert.That(response.DataSubmissionResults, Is.Not.Empty); Assert.That(response.DataSubmissionResults[0].RecordAction, Is.EqualTo(RecordAction.Update), "Expected an Update to occur"); return((int)response.DataSubmissionResults[0].SetId); }
public void Insert() { SimpleDataWebServiceClient webServiceClient = Create(); InMemoryRecord record = ProductionRecords.NewRecord().MarkAsNew(); SubmitDataRequest request = new SubmitDataRequest { Credentials = CreateCredentials(), SubmitDataRecords = new[] { record.ConvertToSubmitDataRecord() } }; SubmitDataResponse response = webServiceClient.SubmitData(request); Assert.That(response.DataSubmissionResults, Is.Not.Null); Assert.That(response.DataSubmissionResults.Length, Is.EqualTo(1)); Assert.That(response.DataSubmissionResults[0].RecordAction, Is.EqualTo(RecordAction.Insert)); Assert.That(response.DataSubmissionResults[0].SetId, Is.GreaterThan(100)); Assert.That(DatabaseRecords.Count, Is.EqualTo(1)); }