Example #1
0
        public async Task Given_Values_When_UpsertVisitItemEntityAsync_Invoked_Then_It_Should_Return_Result(string shortUrl, HttpStatusCode statusCode)
        {
            var record = new VisitItemEntity()
            {
                ShortUrl = shortUrl
            };

            var item = new Mock <ItemResponse <VisitItemEntity> >();

            item.SetupGet(p => p.Resource).Returns(record);
            item.SetupGet(p => p.StatusCode).Returns(statusCode);

            var container = new Mock <Container>();

            container.Setup(p => p.UpsertItemAsync <VisitItemEntity>(It.IsAny <VisitItemEntity>(), It.IsAny <PartitionKey?>(), It.IsAny <ItemRequestOptions>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(item.Object);

            var helper = new Mock <ICosmosDbContainerHelper>();

            helper.Setup(p => p.GetContainerAsync()).ReturnsAsync(container.Object);

            var command = new CosmosDbCommand(helper.Object);

            var result = await command.UpsertItemEntityAsync <VisitItemEntity>(record).ConfigureAwait(false);

            result.Should().Be((int)statusCode);
        }
        public async Task Given_ShortUrl_When_UpsertAsync_With_VisitItemEntity_Invoked_Then_It_Should_Return_Result(HttpStatusCode statusCode)
        {
            var settings = this._mocker.CreateAppSettingsInstance();

            var item = new VisitItemEntity()
            {
                UrlId = Guid.NewGuid()
            };
            var query = new Mock <IQuery>();

            var command = new Mock <ICommand>();

            command.Setup(p => p.UpsertItemEntityAsync <VisitItemEntity>(It.IsAny <VisitItemEntity>())).ReturnsAsync((int)statusCode);

            var service = new ExpanderService(settings.Object, query.Object, command.Object);

            var payload = new ExpanderResponse()
            {
                EntityId      = Guid.NewGuid(),
                UrlId         = Guid.NewGuid(),
                DateGenerated = DateTimeOffset.UtcNow,
                DateUpdated   = DateTimeOffset.UtcNow
            };

            var result = await service.UpsertAsync <VisitItemEntity>(payload).ConfigureAwait(false);

            result.Should().Be((int)statusCode);
        }
Example #3
0
        public void Given_PartitionType_Then_It_Should_Return_Result(PartitionType collection)
        {
            var entity = new VisitItemEntity()
            {
                Collection = collection
            };

            entity.PartitionKey.Should().Be(collection.ToString());
            entity.PartitionKeyPath.Should().Be("/collection");
        }
Example #4
0
        public void Given_NullShortUrl_When_Serialised_Then_It_Should_Throw_Exception()
        {
            var entity = new VisitItemEntity()
            {
                ShortUrl      = null,
                DateGenerated = DateTimeOffset.UtcNow,
            };

            Action action = () => JsonConvert.SerializeObject(entity);

            action.Should().Throw <JsonSerializationException>();
        }
Example #5
0
        public void Given_Values_When_Serialised_Then_It_Should_Return_Result(string shortUrl)
        {
            var entityId   = Guid.NewGuid();
            var collection = PartitionType.Visit;
            var now        = DateTimeOffset.UtcNow;

            var entity = new VisitItemEntity()
            {
                EntityId      = entityId,
                ShortUrl      = shortUrl,
                DateGenerated = now,
            };

            var dateGenerated = JsonConvert.SerializeObject(now);

            var serialised = JsonConvert.SerializeObject(entity);

            serialised.Should().Contain($"\"id\":\"{entityId.ToString()}\"");
            serialised.Should().Contain($"\"collection\":\"{collection.ToString()}\"");
            serialised.Should().Contain($"\"shortUrl\":\"{shortUrl}\"");
            serialised.Should().Contain($"\"dateGenerated\":{dateGenerated}");
            serialised.Should().Contain($"\"requestHeaders\":{{}}");
        }