Exemplo n.º 1
0
        public async Task GetAsync_UserRole_ReturnsMinimalResource()
        {
            using (var env = new TestEnvironment())
            {
                env.SetUser(User01Id, SystemRoles.User);
                env.JsonApiContext.QuerySet.Returns(new QuerySet());
                env.JsonApiContext.PageManager.Returns(new PageManager());

                UserResource resource = await env.Service.GetAsync(User02Id);

                IEnumerable <PropertyInfo> nonNullProperties =
                    resource.GetType().GetProperties().Where(p => p.GetValue(resource) != null);
                Assert.That(nonNullProperties.Select(p => p.Name).ToArray(), Is.EquivalentTo(new[] {
                    nameof(UserResource.Id),
                    nameof(UserResource.StringId),
                    nameof(UserResource.Name),
                    nameof(UserResource.AvatarUrl)
                }));

                Assert.That(resource.Id, Is.EqualTo(User02Id));
                Assert.That(resource.StringId, Is.EqualTo(User02Id));
                Assert.That(resource.Name, Is.EqualTo(User02Name));
                Assert.That(resource.AvatarUrl, Is.EqualTo("user02avatarurl"));
            }
        }