public CustomObject <T> CreateCustomObject <T>(CustomObjectDraft <T> customObjectDraft)
        {
            IClient commerceToolsClient = this.GetService <IClient>();
            var     customObject        = commerceToolsClient.ExecuteAsync(new CustomObjectUpsertCommand <T>(customObjectDraft)).Result;

            return(customObject);
        }
        public void UpdateCustomObject()
        {
            IClient commerceToolsClient = this.customObjectsFixture.GetService <IClient>();

            FooBar fooBar = new FooBar();
            string key    = TestingUtility.RandomString(10);

            CustomObjectDraft <FooBar> customObjectDraft =
                this.customObjectsFixture.GetFooBarCustomObjectDraft(TestingUtility.DefaultContainerName, key, fooBar);

            //Create FooBar Custom Object
            var customObject = commerceToolsClient
                               .ExecuteAsync(new CustomObjectUpsertCommand <FooBar>(customObjectDraft)).Result;

            Assert.Equal(customObjectDraft.Key, customObject.Key);
            Assert.Equal(customObjectDraft.Value.Bar, customObject.Value.Bar);

            //Then Update Custom Object Value
            customObjectDraft.Value.Bar = TestingUtility.RandomString(10);

            var updatedCustomObject = commerceToolsClient
                                      .ExecuteAsync(new CustomObjectUpsertCommand <FooBar>(customObjectDraft)).Result;

            this.customObjectsFixture.CustomObjectsToDelete.Add(updatedCustomObject);

            Assert.Equal(customObjectDraft.Key, updatedCustomObject.Key);
            Assert.Equal(customObjectDraft.Value.Bar, updatedCustomObject.Value.Bar);
        }
        public static async Task WithListOfCustomObjectsAsync <T>(
            IClient client,
            CustomObjectDraft <T> draft,
            Func <CustomObjectDraft <T>, CustomObjectDraft <T> > draftAction,
            Func <List <CustomObject <T> >, Task> func,
            int count = 2
            )
        {
            var resourcesList = new List <CustomObject <T> >();

            for (int i = 1; i <= count; i++)
            {
                var buildDraft = draftAction.Invoke(draft);
                var resource   = await CreateCustomObject(client, buildDraft);

                resourcesList.Add(resource);
            }

            try
            {
                await func(resourcesList);
            }
            finally
            {
                foreach (var resource in resourcesList)
                {
                    await DeleteCustomObject(client, resource);
                }
            }
        }
        public static CustomObjectDraft <T> DefaultCustomObjectDraftWithKey <T>(CustomObjectDraft <T> draft, T value,
                                                                                string key)
        {
            var customObjectDraft = DefaultCustomObjectDraft(draft, value);

            customObjectDraft.Key = key;
            return(customObjectDraft);
        }
        public static CustomObjectDraft <T> DefaultCustomObjectDraft <T>(CustomObjectDraft <T> customObjectDraft, T value)
        {
            var randomInt = TestingUtility.RandomInt();

            customObjectDraft.Key       = $"Key{randomInt}";
            customObjectDraft.Container = TestingUtility.DefaultContainerName;
            customObjectDraft.Value     = value;
            return(customObjectDraft);
        }
        /// <summary>
        /// Get CustomObject Draft
        /// </summary>
        /// <returns></returns>

        public CustomObjectDraft <T> GetCustomObjectDraft <T>(string container, string key, T value, int?version = null)
        {
            CustomObjectDraft <T> draft = new CustomObjectDraft <T>
            {
                Container = container,
                Key       = key,
                Value     = value,
                Version   = version
            };

            return(draft);
        }
Exemple #7
0
        public async Task ShouldUpdateCustomObjectAsync()
        {
            CustomObjectDraft <string> customObjectDraft = new CustomObjectDraft <string>(_testCustomObject.Container, _testCustomObject.Key, "newValue");

            customObjectDraft.Version = _testCustomObject.Version;

            Response <CustomObject <string> > response = await _client.CustomObjects().CreateOrUpdateCustomObjectAsync(customObjectDraft);

            Assert.IsTrue(response.Success);

            CustomObject <string> updatedObject = response.Result;

            Assert.NotNull(updatedObject.Id);
            Assert.AreEqual(_testCustomObject.Id, updatedObject.Id);
            Assert.AreEqual("newValue", updatedObject.Value);

            _testCustomObject = updatedObject;
        }
        public static async Task WithCustomObjectAsync <T>(
            IClient client,
            CustomObjectDraft <T> draft,
            Func <CustomObjectDraft <T>, CustomObjectDraft <T> > draftAction,
            Func <CustomObject <T>, Task> func
            )
        {
            var buildDraft = draftAction.Invoke(draft);
            var resource   = await CreateCustomObject(client, buildDraft);

            try
            {
                await func(resource);
            }
            finally
            {
                await DeleteCustomObject(client, resource);
            }
        }
        public void SerializeCustomObjectDraft()
        {
            ISerializerService serializerService = this.serializationFixture.SerializerService;
            var customObjectDraft = new CustomObjectDraft <CustomFooBar>
            {
                Key       = "key1",
                Container = "container1",
                Value     = new CustomFooBar
                {
                    Foo = "Bar"
                },
                Version = 1
            };
            string result              = serializerService.Serialize(customObjectDraft);
            JToken resultFormatted     = JValue.Parse(result);
            string serialized          = File.ReadAllText("Resources/CustomObjects/FooBarCustomObject.json");
            JToken serializedFormatted = JValue.Parse(serialized);

            serializedFormatted.Should().BeEquivalentTo(resultFormatted);
        }
Exemple #10
0
        public async Task ShouldCreateAndDeleteCustomObjectAsync()
        {
            CustomObjectDraft <string>        customObjectDraft           = Helper.GetTestCustomObjectDraft();
            Response <CustomObject <string> > customObjectCreatedResponse = await _client.CustomObjects().CreateOrUpdateCustomObjectAsync(customObjectDraft);

            Assert.IsTrue(customObjectCreatedResponse.Success);

            CustomObject <string> customObject = customObjectCreatedResponse.Result;

            Assert.NotNull(customObject.Id);

            string deletedCustomObjectId = customObject.Id;
            Response <CustomObject <string> > customObjectResponse = await _client.CustomObjects().DeleteCustomObjectAsync(customObject);

            Assert.IsTrue(customObjectResponse.Success);

            customObjectResponse = await _client.CustomObjects().GetCustomObjectByIdAsync <string>(deletedCustomObjectId);

            Assert.IsFalse(customObjectResponse.Success);
        }
Exemple #11
0
        public void Init()
        {
            _client = Helper.GetClient();

            Task <Response <Project.Project> > projectTask = _client.Project().GetProjectAsync();

            projectTask.Wait();
            Assert.IsTrue(projectTask.Result.Success);

            CustomObjectDraft <string> customObjectDraft = Helper.GetTestCustomObjectDraft();
            Task <Response <CustomObject <string> > > customObjectTask = _client.CustomObjects().CreateOrUpdateCustomObjectAsync(customObjectDraft);

            customObjectTask.Wait();
            Assert.IsTrue(customObjectTask.Result.Success);

            CustomObject <string> customObject = customObjectTask.Result.Result;

            Assert.NotNull(customObject.Id);

            _testCustomObject = customObject;
        }
        public static async Task WithUpdateableCustomObjectAsync <T>(
            IClient client,
            CustomObjectDraft <T> draft,
            Func <CustomObjectDraft <T>, CustomObjectDraft <T> > draftAction,
            Func <CustomObject <T>, CustomObjectDraft <T>, Task <CustomObject <T> > > func
            )
        {
            var buildDraft = draftAction.Invoke(draft);
            var resource   = await CreateCustomObject(client, buildDraft);

            var updatedResource = default(CustomObject <T>);

            try
            {
                updatedResource = await func(resource, buildDraft);
            }
            finally
            {
                await DeleteCustomObject(client, updatedResource ?? resource);
            }
        }
        public static CustomObjectDraft <T> DefaultCustomObjectDraftWithContainerName <T>(CustomObjectDraft <T> draft, string containerName)
        {
            var value             = Activator.CreateInstance <T>();
            var customObjectDraft = DefaultCustomObjectDraft(draft, value);

            customObjectDraft.Container = containerName;
            return(customObjectDraft);
        }