示例#1
0
        public async Task <FlatForRentAnnouncement> InsertFlatForRentAnnouncementAsync()
        {
            var flatForRentAnnouncement = FlatForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://sourceUrl")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                                          .SetPrice(100)
                                          .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                          .Build();
            var entity = new FlatForRentAnnouncementEntity
            {
                Id               = flatForRentAnnouncement.Id,
                Title            = flatForRentAnnouncement.Title,
                Created          = flatForRentAnnouncement.Created,
                CityId           = flatForRentAnnouncement.CityId,
                SourceUrl        = flatForRentAnnouncement.SourceUrl,
                Description      = flatForRentAnnouncement.Description,
                Price            = flatForRentAnnouncement.Price,
                NumberOfRooms    = flatForRentAnnouncement.NumberOfRooms.ConvertToEnum(),
                CityDistricts    = flatForRentAnnouncement.CityDistricts,
                CosmosEntityName = nameof(Domain.FlatForRentAnnouncements.Aggregates.FlatForRentAnnouncement)
            };
            await CosmosStore.AddAsync(entity);

            return(flatForRentAnnouncement);
        }
示例#2
0
        public async Task AddEntityWithoutIdEmptyGeneratedId()
        {
            // Arrange
            var dummy = new Dummy
            {
                Name = "Nick"
            };
            var document         = dummy.ToCosmonautDocument();
            var resourceResponse = document.ToResourceResponse(HttpStatusCode.OK);

            _mockDocumentClient.Setup(x => x.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("databaseName", "dummies"),
                                                                 document.ItIsSameDocument(), It.IsAny <RequestOptions>(), false, CancellationToken.None))
            .ReturnsAsync(resourceResponse);

            var entityStore = new CosmosStore <Dummy>(new CosmonautClient(_mockDocumentClient.Object), "databaseName");

            // Act
            var result = await entityStore.AddAsync(dummy);

            //Assert
            var isGuid = Guid.TryParse(result.Entity.Id, out var guid);

            isGuid.Should().BeTrue();
            guid.Should().NotBeEmpty();
            result.IsSuccess.Should().BeTrue();
            result.ResourceResponse.Resource.Should().NotBeNull();
            result.ResourceResponse.Resource.Should().BeEquivalentTo(document);
            result.Entity.Should().BeEquivalentTo(dummy);
            result.CosmosOperationStatus.Should().Be(CosmosOperationStatus.Success);
            result.ResourceResponse.StatusCode.Should().Be(HttpStatusCode.OK);
        }
示例#3
0
        public async Task AddValidObjectSuccess()
        {
            // Arrange
            var id    = Guid.NewGuid().ToString();
            var dummy = new Dummy
            {
                Id   = id,
                Name = "Nick"
            };
            var document         = dummy.ConvertObjectToDocument();
            var resourceResponse = document.ToResourceResponse(HttpStatusCode.OK);

            _mockDocumentClient.Setup(x => x.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("databaseName", "dummies"),
                                                                 document.ItIsSameDocument(), It.IsAny <RequestOptions>(), false, CancellationToken.None))
            .ReturnsAsync(resourceResponse);

            var entityStore = new CosmosStore <Dummy>(new CosmonautClient(_mockDocumentClient.Object), "databaseName");

            // Act
            var result = await entityStore.AddAsync(dummy);

            //Assert
            result.IsSuccess.Should().BeTrue();
            result.Entity.Should().BeEquivalentTo(dummy);
            result.ResourceResponse.Resource.Should().NotBeNull();
            result.ResourceResponse.Resource.Should().BeEquivalentTo(document);
            result.CosmosOperationStatus.Should().Be(CosmosOperationStatus.Success);
            result.ResourceResponse.StatusCode.Should().Be(HttpStatusCode.OK);
        }
示例#4
0
        public async Task <RoomForRentAnnouncement> InsertRoomForRentAnnouncementAsync()
        {
            var roomForRentAnnouncement = RoomForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://sourceUrl")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetPrice(100)
                                          .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                          .SetRoomTypes(new List <RoomTypeEnumeration> {
                RoomTypeEnumeration.MultiPerson
            })
                                          .Build();
            var entity = new RoomForRentAnnouncementEntity
            {
                Id               = roomForRentAnnouncement.Id,
                Title            = roomForRentAnnouncement.Title,
                Created          = roomForRentAnnouncement.Created,
                CityId           = roomForRentAnnouncement.CityId,
                SourceUrl        = roomForRentAnnouncement.SourceUrl,
                Description      = roomForRentAnnouncement.Description,
                Price            = roomForRentAnnouncement.Price,
                CityDistricts    = roomForRentAnnouncement.CityDistricts,
                RoomTypes        = roomForRentAnnouncement.RoomTypes.Select(x => x.ConvertToEnum()),
                CosmosEntityName = nameof(Domain.RoomForRentAnnouncements.Aggregates.RoomForRentAnnouncement)
            };
            await CosmosStore.AddAsync(entity);

            return(roomForRentAnnouncement);
        }
示例#5
0
        public async Task <T> Kreiraj(T objekat)
        {
            T rezultat = null;

            try
            {
                rezultat = await _cosmosStore.AddAsync(objekat);
            }
            catch (Exception i)
            {
                _dnevnik.LogError("Izuzetak prilikom pristupa bazi podataka.", i);

                throw new ReceptiAPIIzuzetak(500, KonstantneVrednosti.GreskaPrilikomPristupaBaziPodataka);
            }

            return(rezultat);
        }
示例#6
0
        public async Task AddEntityWithoutIdEmptyGeneratedId()
        {
            // Arrange
            var dummy = new Dummy
            {
                Name = "Nick"
            };

            _mockDocumentClient.Setup(x => x.CreateDocumentAsync(It.IsAny <string>(),
                                                                 dummy.GetCosmosDbFriendlyEntity() as Document, null, false))
            .ReturnsAsync(new ResourceResponse <Document>());

            var entityStore = new CosmosStore <Dummy>(_mockDocumentClient.Object, "databaseName", new CosmosDatabaseCreator(_mockDocumentClient.Object), new CosmosCollectionCreator(_mockDocumentClient.Object));

            // Act
            var result = await entityStore.AddAsync(dummy);

            //Assert
            var isGuid = Guid.TryParse(result.Entity.Id, out var guid);

            Assert.True(isGuid);
            Assert.NotEqual(Guid.Empty, guid);
        }
示例#7
0
        public async Task AddValidObjectSuccess()
        {
            // Arrange
            var id    = Guid.NewGuid().ToString();
            var dummy = new Dummy
            {
                Id   = id,
                Name = "Nick"
            };

            _mockDocumentClient.Setup(x => x.CreateDocumentAsync(It.IsAny <string>(),
                                                                 dummy.GetCosmosDbFriendlyEntity() as Document, null, false))
            .ReturnsAsync(new ResourceResponse <Document>());

            var entityStore = new CosmosStore <Dummy>(_mockDocumentClient.Object, "databaseName", new CosmosDatabaseCreator(_mockDocumentClient.Object), new CosmosCollectionCreator(_mockDocumentClient.Object));

            // Act
            var expectedResponse = new CosmosResponse <Dummy>(dummy, CosmosOperationStatus.Success);
            var result           = await entityStore.AddAsync(dummy);

            //Assert
            Assert.Equal(expectedResponse.Entity, result.Entity);
            Assert.Equal(expectedResponse.IsSuccess, result.IsSuccess);
        }