Ejemplo n.º 1
0
        public async Task GetPhones_with_users_a_list_of_phones()
        {
            Phone testPhone1 = new Phone
            {
                id        = "1",
                createdAt = new DateTime(2020, 3, 15),
                Blacklist = true,
                IMEI      = 1234,
                userId    = "1"
            };
            List <Phone> phones = new List <Phone>
            {
                testPhone1,
            };

            string payload           = JsonSerializer.Serialize(phones);
            var    mockHttpClient    = CreateMockHttpClient(payload);
            var    mockApiHttpClient = new MockApiHttpClient(mockHttpClient);

            var users = new List <User> {
                new User
                {
                    id             = "1",
                    createdAt      = new DateTime(2020, 3, 15),
                    name           = "John Doe",
                    organizationId = "123",
                    email          = "*****@*****.**"
                },
                new User
                {
                    id             = "1",
                    createdAt      = new DateTime(2015, 8, 10),
                    name           = "Jane Doe",
                    organizationId = "321",
                    email          = "*****@*****.**"
                }
            };

            var result = (await mockApiHttpClient.GetPhones(users)).ToList();

            Assert.NotNull(result);
            Assert.NotEmpty(result);
            Assert.Equal(2, result.Count);
            Assert.True(PhoneObjectsAreEqual(testPhone1, result[0]), "User objects are not equal");
            Assert.True(PhoneObjectsAreEqual(testPhone1, result[1]), "User objects are not equal");
        }
Ejemplo n.º 2
0
        public async Task GetPhones_with_organization_id_and_user_id_deserializes_a_list_of_phones()
        {
            Phone testPhone1 = new Phone
            {
                id        = "1",
                createdAt = new DateTime(2020, 3, 15),
                Blacklist = true,
                IMEI      = 1234,
                userId    = "1"
            };
            Phone testPhone2 = new Phone
            {
                id        = "2",
                createdAt = new DateTime(2015, 8, 10),
                Blacklist = false,
                IMEI      = 4321,
                userId    = "1"
            };
            List <Phone> phones = new List <Phone>
            {
                testPhone1,
                testPhone2,
            };

            string payload           = JsonSerializer.Serialize(phones);
            var    mockHttpClient    = CreateMockHttpClient(payload);
            var    mockApiHttpClient = new MockApiHttpClient(mockHttpClient);

            var result = (await mockApiHttpClient.GetPhones("1", "1")).ToList();

            Assert.NotNull(result);
            Assert.NotEmpty(result);
            Assert.Equal(2, result.Count);
            Assert.True(PhoneObjectsAreEqual(testPhone1, result[0]), "Phone objects are not equal");
            Assert.True(PhoneObjectsAreEqual(testPhone2, result[1]), "Phone objects are not equal");
        }