コード例 #1
0
        public async Task <PledgeDTO> CreateTestPledge(string consumerIndex = null)
        {
            var consumer = String.IsNullOrEmpty(consumerIndex) ? Consumer : PledgeApiConsumers[consumerIndex];

            var url       = ApiPaths.PLEDGES_BASE_PATH;
            var newPledge = new CreatePledgeDTO
            {
                CO2Footprint         = Helpers.Random.Next(100, 100000),
                ClimatePositiveValue = Helpers.Random.Next(100, 100000)
            };

            var createParam = JsonUtils.SerializeObject(newPledge);
            var response    = await consumer.ExecuteRequest(url, Helpers.EmptyDictionary, createParam, Method.POST);

            if (response.Status != HttpStatusCode.Created)
            {
                return(null);
            }

            var pledge = await PledgeRepository.TryGetAsync(p => p.PartitionKey == PledgeEntity.GeneratePartitionKey() && p.ClientId == consumer.ClientInfo.Account.Id);

            var returnDto = Mapper.Map <PledgeDTO>(pledge);

            this.AddCleanupAction(async() => await this.DeleteTestPledge(consumerIndex));

            return(returnDto);
        }
コード例 #2
0
        public async Task CreatePledge()
        {
            await this.PrepareCreateTestPledge();

            var createdPledge = await this.CreateTestPledge("CreatePledge");

            Assert.NotNull(createdPledge);

            var createdPledgeEntity = (PledgeEntity)await this.PledgeRepository.TryGetAsync(
                p => p.PartitionKey == PledgeEntity.GeneratePartitionKey() && p.ClientId == PledgeApiConsumers["CreatePledge"].ClientInfo.Account.Id);

            createdPledgeEntity.ShouldBeEquivalentTo(createdPledge, o => o.ExcludingMissingMembers());
        }
コード例 #3
0
        public async Task DeletePledge()
        {
            await this.PrepareDeleteTestPledge();

            var url = ApiPaths.PLEDGES_BASE_PATH;

            var deleteResponse = await this.PledgeApiConsumers["DeletePledge"].ExecuteRequest(url, Helpers.EmptyDictionary, null, Method.DELETE);

            Assert.True(deleteResponse.Status == HttpStatusCode.NoContent);

            var deletedPledgeEntity = (PledgeEntity)await this.PledgeRepository.TryGetAsync(
                p => p.PartitionKey == PledgeEntity.GeneratePartitionKey() && p.ClientId == this.PledgeApiConsumers["DeletePledge"].ClientInfo.Account.Id);

            Assert.Null(deletedPledgeEntity);
        }
コード例 #4
0
        public async Task UpdatePledge()
        {
            await this.PrepareUpdateTestPledge();

            var editPledge = new PledgeDTO()
            {
                Id                   = this.TestPledgeUpdate.Id,
                ClientId             = this.TestPledgeUpdate.ClientId,
                CO2Footprint         = Helpers.Random.Next(100, 100000),
                ClimatePositiveValue = Helpers.Random.Next(100, 100000)
            };

            var url      = ApiPaths.PLEDGES_BASE_PATH;
            var body     = JsonUtils.SerializeObject(editPledge);
            var response = await this.PledgeApiConsumers["UpdatePledge"].ExecuteRequest(url, Helpers.EmptyDictionary, body, Method.PUT);

            Assert.True(response.Status == HttpStatusCode.NoContent);

            var editedPledgeEntity = (PledgeEntity)await this.PledgeRepository.TryGetAsync(
                p => p.PartitionKey == PledgeEntity.GeneratePartitionKey() && p.ClientId == this.PledgeApiConsumers["UpdatePledge"].ClientInfo.Account.Id);

            editedPledgeEntity.ShouldBeEquivalentTo(editPledge, o => o.ExcludingMissingMembers().Excluding(p => p.ClientId));
        }