Beispiel #1
0
        public void TestPersistAttributeTypeScope()
        {
            var s = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer());

            // Add a new entity to the original model, it should not be serialized!
            new Engine.WorldRendering.Entity();

            var strm = new MemoryStream();

            var writer = new StreamWriter(strm);

            s.Serialize(model, writer);


            var deserialized = new Data.ModelContainer();

            writer.Flush();

            strm.Position = 0;

            // For testing
            string serialized = getStringFromStream(strm);

            SimpleModelObject.CurrentModelContainer = deserialized;

            s.Deserialize(new StreamReader(strm));


            Assert.AreNotEqual(model.Objects.Count, deserialized.Objects.Count);
            Assert.AreEqual(model.Objects[0].ToString(), deserialized.Objects[0].ToString());
            Assert.AreEqual(model.Objects[1].ToString(), deserialized.Objects[1].ToString());
        }
        private async Task <TResponse> SendAsJsonAsync <TResponse, TRequest>(HttpMethod httpMethod, string uri, TRequest request)
        {
            HttpContent httpContent = null;

            if (request != null)
            {
                var memoryStream = new MemoryStream();
                ModelSerializer.Serialize <TRequest>(request, memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);
                httpContent = new StreamContent(memoryStream);
                httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            }

            using (var httpRequest = new HttpRequestMessage(httpMethod, uri))
            {
                using (httpContent)
                {
                    httpRequest.Content = httpContent;

                    using (var response = await HttpClient.SendAsync(httpRequest, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false))
                    {
                        using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
                        {
                            CheckSuccessStatusCode(response, stream);

                            return(ModelSerializer.Deserialize <TResponse>(stream));
                        }
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new log item.
        /// </summary>
        /// <param name="model">Information about representation of log item.</param>
        /// <returns>Representation of just created log item.</returns>
        public async Task <LogItem> AddLogItemAsync(AddLogItemRequest model)
        {
            var uri = BaseUri.Append($"{Project}/log");

            if (model.Attach == null)
            {
                var body     = ModelSerializer.Serialize <AddLogItemRequest>(model);
                var response = await _httpClient.PostAsync(uri, new StringContent(body, Encoding.UTF8, "application/json")).ConfigureAwait(false);

                response.VerifySuccessStatusCode();
                return(ModelSerializer.Deserialize <LogItem>(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
            }
            else
            {
                var body = ModelSerializer.Serialize <List <AddLogItemRequest> >(new List <AddLogItemRequest> {
                    model
                });
                var multipartContent = new MultipartFormDataContent();
                multipartContent.Add(new StringContent(body, Encoding.UTF8, "application/json"), "json_request_part");
                multipartContent.Add(new ByteArrayContent(model.Attach.Data, 0, model.Attach.Data.Length), "file", model.Attach.Name);
                var response = await _httpClient.PostAsync(uri, multipartContent).ConfigureAwait(false);

                response.VerifySuccessStatusCode();
                var c = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(ModelSerializer.Deserialize <Responses>(c).LogItems[0]);
            }
        }
        public async Task <LogItemCreatedResponse> CreateAsync(CreateLogItemRequest request)
        {
            var uri = $"{ProjectName}/log";

            if (request.Attach == null)
            {
                return(await PostAsJsonAsync <LogItemCreatedResponse, CreateLogItemRequest>(uri, request));
            }
            else
            {
                var body = ModelSerializer.Serialize <List <CreateLogItemRequest> >(new List <CreateLogItemRequest> {
                    request
                });
                var multipartContent = new MultipartFormDataContent();

                var jsonContent = new StringContent(body, Encoding.UTF8, "application/json");
                multipartContent.Add(jsonContent, "json_request_part");

                var byteArrayContent = new ByteArrayContent(request.Attach.Data, 0, request.Attach.Data.Length);
                byteArrayContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(request.Attach.MimeType);
                multipartContent.Add(byteArrayContent, "file", request.Attach.Name);

                var response = await HttpClient.PostAsync(uri, multipartContent).ConfigureAwait(false);

                response.VerifySuccessStatusCode();
                var c = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(ModelSerializer.Deserialize <Responses>(c).LogItems[0]);
            }
        }
Beispiel #5
0
        public void TestSerializeCustomStringSerializerAttribute()
        {
            var model = new ModelContainer();

            SimpleModelObject.CurrentModelContainer = model;

            var obj = new TestCustomObject();

            obj.Text = "Hello ";

            var strm       = new MemoryStream();
            var writer     = new StreamWriter(strm);
            var serializer = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer());

            serializer.QueueForSerialization(obj);

            serializer.Serialize(writer);
            writer.Flush();

            strm.Position = 0;

            var str = getStringFromStream(strm);


            var objects = serializer.Deserialize(new StreamReader(strm));

            Assert.AreEqual(obj, objects[0]);
        }
Beispiel #6
0
        public ActionResult Test(OrderModel order)
        {
            // Result
            this.ViewBag.TriggerAction = @"Trigger Action:「Test(OrderModel order)」";
            this.ViewBag.Result        = ModelSerializer.Serialize(order, "order");

            // Return
            return(View());
        }
Beispiel #7
0
        public ActionResult Test(EmployeeModel employee)
        {
            // Result
            this.ViewBag.TriggerAction = @"Trigger Action:「Test(EmployeeModel employee)」";
            this.ViewBag.Result        = ModelSerializer.Serialize(employee, "employee");

            // Return
            return(View());
        }
Beispiel #8
0
        /// <summary>
        /// Merge several launches.
        /// </summary>
        /// <param name="model">Request for merging.</param>
        /// <returns>Returns the model of merged launches.</returns>
        public async Task <Launch> MergeLaunchesAsync(MergeLaunchesRequest model)
        {
            var uri      = BaseUri.Append($"{Project}/launch/merge");
            var body     = ModelSerializer.Serialize <MergeLaunchesRequest>(model);
            var response = await _httpClient.PostAsync(uri, new StringContent(body, Encoding.UTF8, "application/json")).ConfigureAwait(false);

            response.VerifySuccessStatusCode();
            return(ModelSerializer.Deserialize <Launch>(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
        }
Beispiel #9
0
        /// <summary>
        /// Creates a new launch.
        /// </summary>
        /// <param name="request">Information about representation of launch.</param>
        /// <returns>Representation of just created launch.</returns>
        public virtual async Task <LaunchCreatedResponse> StartAsync(StartLaunchRequest request)
        {
            var uri      = BaseUri.Append($"{ProjectName}/launch");
            var body     = ModelSerializer.Serialize <StartLaunchRequest>(request);
            var response = await HttpClient.PostAsync(uri, new StringContent(body, Encoding.UTF8, "application/json")).ConfigureAwait(false);

            response.VerifySuccessStatusCode();
            return(ModelSerializer.Deserialize <LaunchCreatedResponse>(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
        }
Beispiel #10
0
        /// <summary>
        /// Update specified launch.
        /// </summary>
        /// <param name="id">ID of launch to update.</param>
        /// <param name="request">Information about launch.</param>
        /// <returns>A message from service.</returns>
        public virtual async Task <MessageResponse> UpdateAsync(long id, UpdateLaunchRequest request)
        {
            var uri      = BaseUri.Append($"{ProjectName}/launch/{id}/update");
            var body     = ModelSerializer.Serialize <UpdateLaunchRequest>(request);
            var response = await HttpClient.PutAsync(uri, new StringContent(body, Encoding.UTF8, "application/json")).ConfigureAwait(false);

            response.VerifySuccessStatusCode();
            return(ModelSerializer.Deserialize <MessageResponse>(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
        }
        /// <summary>
        /// Assign issues to specified test items.
        /// </summary>
        /// <param name="model">Information about test items and their issues.</param>
        /// <returns>A list of assigned issues.</returns>
        public virtual async Task <List <Issue> > AssignTestItemIssuesAsync(AssignTestItemIssuesRequest model)
        {
            var uri      = BaseUri.Append($"{Project}/item");
            var body     = ModelSerializer.Serialize <AssignTestItemIssuesRequest>(model);
            var response = await _httpClient.PutAsync(uri, new StringContent(body, Encoding.UTF8, "application/json")).ConfigureAwait(false);

            response.VerifySuccessStatusCode();
            return(ModelSerializer.Deserialize <List <Issue> >(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
        }
        /// <summary>
        /// Creates a new test item.
        /// </summary>
        /// <param name="id">ID of parent item.</param>
        /// <param name="model">Information about representation of test item.</param>
        /// <returns>Representation of created test item.</returns>
        public virtual async Task <TestItem> StartTestItemAsync(string id, StartTestItemRequest model)
        {
            var uri      = BaseUri.Append($"{Project}/item/{id}");
            var body     = ModelSerializer.Serialize <StartTestItemRequest>(model);
            var response = await _httpClient.PostAsync(uri, new StringContent(body, Encoding.UTF8, "application/json")).ConfigureAwait(false);

            response.VerifySuccessStatusCode();
            return(ModelSerializer.Deserialize <TestItem>(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
        }
Beispiel #13
0
        public Allocation Allocate(CreditNote creditNote, Allocation allocation)
        {
            string requestXml = ModelSerializer.Serialize(allocation);

            string responseXml = _proxy.ApplyAllocation(creditNote, requestXml);

            Response response = ModelSerializer.DeserializeTo <Response>(responseXml);

            return(response.GetTypedProperty <Allocation>().First());
        }
Beispiel #14
0
        /// <summary>
        /// Creates the specified user filter.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual async Task <UserFilterCreatedResponse> CreateAsync(CreateUserFilterRequest model)
        {
            var uri = BaseUri.Append($"{ProjectName}/filter");

            var body     = ModelSerializer.Serialize <CreateUserFilterRequest>(model);
            var response = await HttpClient.PostAsync(uri, new StringContent(body, Encoding.UTF8, "application/json")).ConfigureAwait(false);

            response.VerifySuccessStatusCode();
            return(ModelSerializer.Deserialize <UserFilterCreatedResponse>(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
        }
        /// <summary>
        /// updates the project preference for user
        /// </summary>
        /// <param name="model"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public virtual async Task <UpdatePreferencesResponse> UpdatePreferencesAsync(UpdatePreferenceRequest model, string userName)
        {
            var uri  = BaseUri.Append($"project/{Project}/preference/{userName}");
            var body = ModelSerializer.Serialize <UpdatePreferenceRequest>(model);

            var response = await _httpClient.PutAsync(uri, new StringContent(body, Encoding.UTF8, "application/json")).ConfigureAwait(false);

            response.VerifySuccessStatusCode();
            return(ModelSerializer.Deserialize <UpdatePreferencesResponse>(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
        }
        public void EndScope(ILogScope logScope)
        {
            var communicationMessage = new EndScopeCommunicationMessage
            {
                Id      = logScope.Id,
                EndTime = logScope.EndTime.Value,
                Status  = logScope.Status
            };

            Console.WriteLine(ModelSerializer.Serialize <EndScopeCommunicationMessage>(communicationMessage));
        }
Beispiel #17
0
        /// <summary>
        /// Updates the specified items in the remote repository
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <param name="itemToUpdate">The item to update.</param>
        /// <returns></returns>
        public TModel UpdateOrCreate <TModel>(TModel itemToUpdate)
            where TModel : EndpointModelBase
        {
            string requestXml = ModelSerializer.Serialize(itemToUpdate);

            string responseXml = _proxy.UpdateOrCreateElements(typeof(TModel).Name, requestXml);

            Response response = ModelSerializer.DeserializeTo <Response>(responseXml);

            return(response.GetTypedProperty <TModel>().First());
        }
Beispiel #18
0
        /// <summary>
        /// Updates the specified items in the remote repository
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <param name="itemsToUpdate">The items to update.</param>
        /// <returns></returns>
        public IEnumerable <TModel> UpdateOrCreate <TModel>(ICollection <TModel> itemsToUpdate)
            where TModel : EndpointModelBase
        {
            string requestXml = ModelSerializer.Serialize(itemsToUpdate);

            string responseXml = _proxy.UpdateOrCreateElements(typeof(TModel).Name, requestXml);

            Response response = ModelSerializer.DeserializeTo <Response>(responseXml);

            return(response.GetTypedProperty <TModel>());
        }
        public ActionResult GetListOfCompaniesWithSizes()
        {
            string data = ModelSerializer.Serialize(ModelSerializerModel.Data, new ModelFieldCollection()
            {
                new ModelField("Company"),
                new ModelField("Size")
            });

            X.Msg.Alert("Companies", data).Show();

            return(this.Direct());
        }
Beispiel #20
0
        /// <summary>
        /// Finishes specified launch.
        /// </summary>
        /// <param name="id">ID of specified launch.</param>
        /// <param name="model">Information about representation of launch to finish.</param>
        /// <param name="force">Force finish launch even if test items are in progress.</param>
        /// <returns>A message from service.</returns>
        public async Task <Message> FinishLaunchAsync(string id, FinishLaunchRequest model, bool force = false)
        {
            var uri = BaseUri.Append($"{Project}/launch/{id}");

            uri = force == true?uri.Append("/stop") : uri.Append("/finish");

            var body     = ModelSerializer.Serialize <FinishLaunchRequest>(model);
            var response = await _httpClient.PutAsync(uri, new StringContent(body, Encoding.UTF8, "application/json")).ConfigureAwait(false);

            response.VerifySuccessStatusCode();
            return(ModelSerializer.Deserialize <Message>(await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
        }
        public void BeginScope(ILogScope logScope)
        {
            var communicationMessage = new BeginScopeCommunicationMessage
            {
                Id            = logScope.Id,
                ParentScopeId = logScope.Parent?.Id,
                Name          = logScope.Name,
                BeginTime     = logScope.BeginTime
            };

            Console.WriteLine(ModelSerializer.Serialize <BeginScopeCommunicationMessage>(communicationMessage));
        }
        public void Simulate()
        {
            if (lastSave + interval > DateTime.Now)
            {
                return;
            }

            using (var fs = File.Open(file, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
                using (var writer = new StreamWriter(fs))
                    serializer.Serialize(TW.Data, writer);

            lastSave = DateTime.Now;
        }
Beispiel #23
0
        public void serialize_method_can_serialize_properties_that_are_populated()
        {
            Contact contact = new Contact {
                Name = "Jason", Phones = new Phones {
                    new Phone {
                        PhoneAreaCode = "04"
                    }
                }
            };

            var xml = ModelSerializer.Serialize(contact);

            Assert.IsTrue(xml.Contains("<PhoneAreaCode>04</PhoneAreaCode>"));
        }
Beispiel #24
0
        public void serialize_method_can_omit_string_properties_that_are_null()
        {
            Contact contact = new Contact {
                Name = "Jason", Phones = new Phones {
                    new Phone {
                        PhoneAreaCode = null
                    }
                }
            };

            var xml = ModelSerializer.Serialize(contact);

            Assert.IsFalse(xml.Contains("PhoneAreaCode"));
        }
Beispiel #25
0
        public void serialize_method_can_serialise_properties_that_are_empty_strings()
        {
            Contact contact = new Contact {
                Name = "Jason", Phones = new Phones {
                    new Phone {
                        PhoneAreaCode = ""
                    }
                }
            };

            var xml = ModelSerializer.Serialize(contact);

            Assert.IsTrue(xml.Contains("<PhoneAreaCode />"));
        }
Beispiel #26
0
        private Task <TResponse> SendAsJsonAsync <TResponse, TRequest>(HttpMethod httpMethod, string uri, TRequest request)
        {
            HttpContent httpContent = null;

            if (request != null)
            {
                var memoryStream = new MemoryStream();
                ModelSerializer.Serialize <TRequest>(request, memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);
                httpContent = new StreamContent(memoryStream);
                httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            }

            return(SendHttpRequestAsync <TResponse>(httpMethod, uri, httpContent));
        }
Beispiel #27
0
        public ActionResult Test(string id, DateTime birthday, [GenderType] GenderType?genderType)
        {
            // Employee
            var employee = new EmployeeModel();

            employee.Id         = id;
            employee.Birthday   = birthday;
            employee.GenderType = genderType;

            // Result
            this.ViewBag.TriggerAction = @"Trigger Action:「Test(string id, DateTime birthday, [GenderType]GenderType? genderType)」";
            this.ViewBag.Result        = ModelSerializer.Serialize(employee);

            // Return
            return(View());
        }
        public void TestAendringDefinitionModelSerializer()
        {
            var sut   = new ModelSerializer();
            var input = new AendringDefinition()
            {
                Targets = new[] { new Stk()
                                  {
                                      NummerStrong = 3, ParentContext = new Paragraf()
                                      {
                                          NummerStrong = "3 a"
                                      }
                                  } }
            };
            var serialize = sut.Serialize(input);

            Assert.NotNull(XDocument.Parse(serialize));
        }
Beispiel #29
0
        public void TestSerializeObjectsTree()
        {
            var model = new ModelContainer();

            SimpleModelObject.CurrentModelContainer = model;

            var array1 = new TestObjectArray();
            var array2 = new TestObjectArray();

            var obj1 = new TestObject {
                Getal = 1
            };
            var obj2 = new TestObject {
                Getal = 2
            };
            var obj3 = new TestObject {
                Getal = 3
            };
            var obj4 = new TestObject {
                Getal = 4
            };
            var obj5 = new TestObject {
                Getal = 5
            };

            array1.Objects.Add(obj1);
            array2.Objects.Add(obj2);
            array2.Objects.Add(obj3);
            obj3.Object = obj4;
            obj4.Object = obj4;
            obj5.Object = obj5;


            var strm       = new MemoryStream();
            var writer     = new StreamWriter(strm);
            var serializer = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer());

            serializer.QueueForSerialization(array2);

            serializer.Serialize(writer);
            writer.Flush();

            strm.Position = 0;

            var str = getStringFromStream(strm);
        }
Beispiel #30
0
        public void TestSerializeArray()
        {
            var array = new TestObjectArray();

            array.Objects = new List <TestObject>();
            array.Objects.Add(object1);
            array.Objects.Add(object2);



            var s = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer());

            var strm = new MemoryStream();

            var writer = new StreamWriter(strm);

            s.Serialize(model, writer);


            var deserialized = new Data.ModelContainer();

            writer.Flush();

            strm.Position = 0;

            // For testing
            string serialized = getStringFromStream(strm);

            SimpleModelObject.CurrentModelContainer = deserialized;
            s = new ModelSerializer(StringSerializer.Create(), new LoadedTypeSerializer());
            s.Deserialize(new StreamReader(strm));


            Assert.AreEqual(model.Objects.Count, deserialized.Objects.Count);
            Assert.AreEqual(model.Objects[0].ToString(), deserialized.Objects[0].ToString());
            Assert.AreEqual(model.Objects[1].ToString(), deserialized.Objects[1].ToString());
            Assert.AreEqual(model.Objects[2].ToString(), deserialized.Objects[2].ToString());
        }