Example #1
0
        public async Task UpdateAsync_SystemAdminRoleDifferentUser()
        {
            using (var env = new TestEnvironment())
            {
                env.SetUser("user02", SystemRoles.SystemAdmin);
                var newConfig = new TranslateProjectUserConfig {
                    SelectedTextRef = "text02"
                };
                env.JsonApiContext.AttributesToUpdate.Returns(new Dictionary <AttrAttribute, object>
                {
                    { env.GetAttribute("translate-config"), newConfig }
                });
                env.JsonApiContext.RelationshipsToUpdate.Returns(new Dictionary <RelationshipAttribute, object>());

                var projectUser = new SFProjectUserResource
                {
                    Id = "projectuser01",
                    TranslateConfig = newConfig
                };
                SFProjectUserResource updatedProjectUser = await env.Service.UpdateAsync(projectUser.Id, projectUser);

                Assert.That(updatedProjectUser, Is.Not.Null);
                Assert.That(updatedProjectUser.TranslateConfig.SelectedTextRef, Is.EqualTo("text02"));
            }
        }
Example #2
0
        public void UpdateAsync_UserRoleDifferentUser()
        {
            using (var env = new TestEnvironment())
            {
                env.SetUser("user02", SystemRoles.User);
                var newConfig = new TranslateProjectUserConfig {
                    SelectedTextRef = "text02"
                };
                env.JsonApiContext.AttributesToUpdate.Returns(new Dictionary <AttrAttribute, object>
                {
                    { env.GetAttribute("translate-config"), newConfig }
                });
                env.JsonApiContext.RelationshipsToUpdate.Returns(new Dictionary <RelationshipAttribute, object>());

                var projectUser = new SFProjectUserResource
                {
                    Id = "projectuser01",
                    TranslateConfig = newConfig
                };
                var ex = Assert.ThrowsAsync <JsonApiException>(async() =>
                {
                    await env.Service.UpdateAsync(projectUser.Id, projectUser);
                });

                Assert.That(ex.GetStatusCode(), Is.EqualTo(StatusCodes.Status403Forbidden));
            }
        }