コード例 #1
0
ファイル: Tests_Accounts.cs プロジェクト: lulzzz/tellma
        public async Task Test04()
        {
            var accountTypeId = Shared.Get <AccountType>("AccountType_SM").Id;

            // Prepare a well formed entity
            var dtoForSave = new AccountForSave
            {
                Name             = "Accounts Payable",
                Name2            = "مستحقات",
                Code             = "Payables",
                AccountTypeId    = accountTypeId,
                ClassificationId = null,
                CurrencyId       = "ETB",
                CenterId         = Shared.Get <Center>("Center_Child").Id,
            };

            // Save it
            var dtosForSave = new List <AccountForSave> {
                dtoForSave
            };
            var response = await Client.PostAsJsonAsync(Url, dtosForSave);

            // Assert that the response status code is a happy 200 OK
            Output.WriteLine(await response.Content.ReadAsStringAsync());
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            // Assert that the response is well-formed singleton of Account
            var responseData = await response.Content.ReadAsAsync <EntitiesResponse <Account> >();

            Assert.Single(responseData.Result);

            // Assert that the result matches the saved entity
            Assert.Equal("Account", responseData.CollectionName);

            // Retreve the entity from the entities
            var responseDto = responseData.Result.SingleOrDefault();

            Assert.NotNull(responseDto?.Id);
            Assert.Equal(dtoForSave.Name, responseDto.Name);
            Assert.Equal(dtoForSave.Name2, responseDto.Name2);
            Assert.Equal(dtoForSave.Name3, responseDto.Name3);
            Assert.Equal(dtoForSave.Code, responseDto.Code);
            Assert.Equal(dtoForSave.AccountTypeId, responseDto.AccountTypeId);
            Assert.Equal(dtoForSave.ClassificationId, responseDto.ClassificationId);
            Shared.Set("Account_Payables", responseDto);
        }
コード例 #2
0
ファイル: Tests_Accounts.cs プロジェクト: lulzzz/tellma
        public async Task Test07()
        {
            var accountTypeId = Shared.Get <AccountType>("AccountType_SM").Id;

            // Prepare a DTO for save, that contains leading and
            // trailing spaces in some string properties
            var dtoForSave = new AccountForSave
            {
                Name             = "  Accounts Receivable", // Leading space
                Name2            = "مطلوبات",
                Code             = "Receivables  ",         // Trailing space
                ClassificationId = null,
                AccountTypeId    = accountTypeId,
                CurrencyId       = "ETB",
                CenterId         = Shared.Get <Center>("Center_Child").Id,
            };

            // Call the API
            var response = await Client.PostAsJsonAsync(Url, new List <AccountForSave> {
                dtoForSave
            });

            Output.WriteLine(await response.Content.ReadAsStringAsync());

            // Confirm that the response is well-formed
            var responseData = await response.Content.ReadAsAsync <EntitiesResponse <Account> >();

            var responseDto = responseData.Result.FirstOrDefault();

            // Confirm the entity was saved
            Assert.NotEqual(0, responseDto.Id);

            // Confirm that the leading and trailing spaces have been trimmed
            Assert.Equal(dtoForSave.Name?.Trim(), responseDto.Name);
            Assert.Equal(dtoForSave.Code?.Trim(), responseDto.Code);

            // share the entity, for the subsequent delete test
            Shared.Set("Account_Receivables", responseDto);
        }