Exemplo n.º 1
0
        public async Task <IActionResult> Create(
            string category,
            string collection,
            string key,
            [FromBody] MetadataModelContract model)
        {
            await _service.Add(category, collection, key, model.Data, model.Keywords);

            return(Created(Request.GetRelativeUrl($"api/v2/{category}/{collection}/{key}"), model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Update(
            string category,
            string collection,
            string key,
            [FromBody] MetadataModelContract model)
        {
            await _service.Upsert(category, collection, key, model.Data, model.Keywords);

            return(Ok(new { Message = "Updated successfully" }));
        }
Exemplo n.º 3
0
        public void CanDeleteMetadata()
        {
            // arrange
            var client     = GetClient();
            var category   = "Integration";
            var collection = "Tests";
            var key        = "486987";

            var expected = new MetadataModelContract
            {
                Data = JsonConvert.SerializeObject(new Dictionary <string, string>
                {
                    { "accountNumber", key },
                    { "marginAccount", "MA01" },
                    { "referenceAccount", "RF11" },
                    { "bankIdentificationReference", "BIR11" },
                })
            };

            MetadataModelContract actual        = null;
            ApiException          httpException = null;

            $"Given the metadata for category: {category} collection: {collection} key: {key}"
            .x(async() =>
            {
                await client.Create(category, collection, key, expected);
            });

            $"When try to delete metadata for the category: {category} collection: {collection} key: {key}"
            .x(async() =>
            {
                await client.Delete(category, collection, key);
            });

            $"And try to get the metadata for the category: {category} collection: {collection} key: {key}"
            .x(async() =>
            {
                try
                {
                    actual = await client.Get(category, collection, key);
                }
                catch (ApiException exp)
                {
                    httpException = exp;
                }
            });

            "Then the fetched metadata should be null"
            .x(() =>
            {
                Assert.Null(actual);
                Assert.NotNull(httpException);
            });
        }
Exemplo n.º 4
0
        public void CanUpdateMetadata()
        {
            // arrange
            var client     = GetClient();
            var category   = "Integration";
            var collection = "Tests";
            var key        = "456988";

            var expected = new MetadataModelContract
            {
                Data = JsonConvert.SerializeObject(new Dictionary <string, string>
                {
                    { "accountNumber", key },
                    { "marginAccount", "MA02" },
                    { "referenceAccount", "RF12" },
                    { "bankIdentificationReference", "BIR12" },
                })
            };

            MetadataModelContract actual = null;

            $"Given the metadata for category: {category} collection: {collection} key: {key}"
            .x(async() =>
            {
                await client.Create(category, collection, key, expected);
            });

            $"When try to update metadata for the category: {category} collection: {collection} key: {key}"
            .x(async() =>
            {
                expected.Data = JsonConvert.SerializeObject(new Dictionary <string, string>
                {
                    { "accountNumber", key },
                    { "referenceAccount", "SomeNewRef" }
                });

                await client.Update(category, collection, key, expected);
            });

            $"And try to get metadata for the category: {category} collection: {collection} key: {key}"
            .x(async() =>
            {
                actual = await client.Get(category, collection, key);
            });

            "Then the fetched metadata should be same as updated metadata"
            .x(() =>
            {
                Assert.NotNull(actual);
                actual.Should().BeEquivalentTo(expected);
            });
        }
Exemplo n.º 5
0
        public void ShouldNotAddKeyMultipleTimesEvenInDifferentCase()
        {
            var client     = GetClient();
            var category   = "Integration";
            var collection = "Tests";
            var key        = "Case-Sensitive-Key";

            var expected = new MetadataModelContract
            {
                Data = JsonConvert.SerializeObject(new Dictionary <string, string>
                {
                    { "accountNumber", key },
                    { "marginAccount", "MA03" },
                    { "referenceAccount", "RF13" },
                    { "bankIdentificationReference", "BIR13" },
                })
            };

            ApiException httpException = null;

            $"Given the metadata for category: {category} collection: {collection} key: {key}"
            .x(async() =>
            {
                await client.Create(category, collection, key, expected);
            });

#pragma warning disable CA1308 // Normalize strings to uppercase
            key = key.ToLower(CultureInfo.InvariantCulture);
#pragma warning restore CA1308 // Normalize strings to uppercase

            $"When try to add metadata again for same category: {category} collection: {collection} key: {key} but in different case"
            .x(async() =>
            {
                try
                {
                    await client.Create(category, collection, key, expected);
                }
                catch (ApiException exp)
                {
                    httpException = exp;
                }
            });

            $"Then system should return 409 Conflict"
            .x(() =>
            {
                Assert.NotNull(httpException);
                Assert.Equal(HttpStatusCode.Conflict, httpException.StatusCode);
                Assert.NotNull(httpException.Message);
            });
        }
Exemplo n.º 6
0
        public void ShouldNotAddKeyMultipleTimes()
        {
            var client     = GetClient();
            var category   = "Integration";
            var collection = "Tests";
            var key        = "Some-Unique-Key";

            var expected = new MetadataModelContract
            {
                Data = JsonConvert.SerializeObject(new Dictionary <string, string>
                {
                    { "accountNumber", key },
                    { "marginAccount", "MA02" },
                    { "referenceAccount", "RF12" },
                    { "bankIdentificationReference", "BIR12" },
                })
            };

            ApiException httpException = null;

            $"Given the metadata for category: {category} collection: {collection} key: {key}"
            .x(async() =>
            {
                await client.Create(category, collection, key, expected);
            });

            $"When try to add metadata again for category: {category} collection: {collection} key: {key}"
            .x(async() =>
            {
                try
                {
                    await client.Create(category, collection, key, expected);
                }
                catch (ApiException exp)
                {
                    httpException = exp;
                }
            });

            $"Then system should return 409 Conflict"
            .x(() =>
            {
                Assert.NotNull(httpException);
                Assert.Equal(HttpStatusCode.Conflict, httpException.StatusCode);
                Assert.NotNull(httpException.Message);
            });
        }
Exemplo n.º 7
0
 public static (T metadata, IList <string> keywords) GetWithKeywords <T>(this MetadataModelContract metadata)
 => (JsonConvert.DeserializeObject <T>(metadata.Data),
Exemplo n.º 8
0
 public static T Get <T>(this MetadataModelContract metadata)
 => JsonConvert.DeserializeObject <T>(metadata.Data);
Exemplo n.º 9
0
 public static MetadataModel Map(MetadataModelContract model)
 => new MetadataModel
 {
     Data     = model.Data,
     Keywords = model.Keywords,
 };