public void Delete_passes_through() { Models.Client passThrougResult = null; var cmdletMock = CmdletMock.CreateMock(); cmdletMock.Setup(cmdlet => cmdlet.WriteObject(It.IsAny <Models.Client>())) .Callback <object>(p => passThrougResult = p as Models.Client); var ctxName = Guid.NewGuid().ToString(); using (var ctx = _dbContextFixture.GetContext(ctxName)) { ctx.Clients.Add(new Models.Client { ClientId = "MyClientId", AllowedScopes = new[] { "Scope1" } }.ToEntity()); ctx.SaveChanges(); } using (var ctx = _dbContextFixture.GetContext(ctxName)) { var controller = new ClientController(ctx, cmdletMock.Object); controller.DeleteClient("MyClientId", true); } Assert.Equal("MyClientId", passThrougResult?.ClientId); }
public void Deletes_from_database() { Models.ApiResource passThrougResult = null; var cmdletMock = CmdletMock.CreateMock(); cmdletMock.Setup(cmdlet => cmdlet.WriteObject(It.IsAny <Models.ApiResource>())) .Callback <object>(p => passThrougResult = p as Models.ApiResource); var ctxName = Guid.NewGuid().ToString(); using (var ctx = _dbContextFixture.GetContext(ctxName)) { ctx.ApiResources.Add(new Models.ApiResource { Name = "MyResource" }.ToEntity()); ctx.SaveChanges(); } using (var ctx = _dbContextFixture.GetContext(ctxName)) { var controller = new ApiResourceController(ctx, cmdletMock.Object); controller.DeleteApiResource("MyResource", true); } using (var ctx = _dbContextFixture.GetContext(ctxName)) { var resources = ctx.ApiResources.ToList(); Assert.Empty(resources); Assert.Equal("MyResource", passThrougResult?.Name); } }
public async Task Updates_in_database() { var ctxName = Guid.NewGuid().ToString(); var cmdletMock = CmdletMock.CreateMock(); var newResource = new Models.ApiResource { Name = "MyResource", Scopes = new[] { new Models.Scope { Name = "Scope1" } } }; using (var ctx = _dbContextFixture.GetContext(ctxName)) { var controller = new ApiResourceController(ctx, cmdletMock.Object); controller.AddApiResource(newResource, false); } Models.ApiResource setResource; using (var ctx = _dbContextFixture.GetContext(ctxName)) { var store = new ResourceStore(ctx, NullLogger <ResourceStore> .Instance); setResource = await store.FindApiResourceAsync("MyResource"); } setResource.Scopes = new[] { new Models.Scope { Name = "Scope1" }, new Models.Scope { Name = "Scope2" } }; using (var ctx = _dbContextFixture.GetContext(ctxName)) { var controller = new ApiResourceController(ctx, cmdletMock.Object); controller.UpdateApiResource(setResource, "MyOtherResource", false); } using (var ctx = _dbContextFixture.GetContext(ctxName)) { var store = new ResourceStore(ctx, NullLogger <ResourceStore> .Instance); var resource = await store.FindApiResourceAsync("MyOtherResource"); Assert.NotNull(resource); Assert.Equal(2, resource.Scopes.Count); } }
public void Add_passes_through() { var cmdletMock = CmdletMock.CreateMock(); var ctxName = Guid.NewGuid().ToString(); var newClient = new Models.Client { ClientId = "MyClientId" }; using (var ctx = _dbContextFixture.GetContext(ctxName)) { var controller = new ClientController(ctx, cmdletMock.Object); controller.AddClient(newClient, true); } cmdletMock.Verify(cmdlet => cmdlet.WriteObject(newClient), Times.Exactly(1)); }
public async Task Adds_to_database() { var cmdletMock = CmdletMock.CreateMock(); var ctxName = Guid.NewGuid().ToString(); var newClient = new Models.Client { ClientId = "MyClientId", AllowedScopes = new[] { "Scope1" }, AllowedGrantTypes = new[] { "Grant1" }, AllowedCorsOrigins = new[] { "Origin1" }, Claims = new[] { new Claim("ClaimType1", "Claim1"), }, Properties = new Dictionary <string, string> { { "Key1", "Value1" } }, RedirectUris = new[] { "Redirect1" } }; using (var ctx = _dbContextFixture.GetContext(ctxName)) { var controller = new ClientController(ctx, cmdletMock.Object); controller.AddClient(newClient, false); } using (var ctx = _dbContextFixture.GetContext(ctxName)) { var clients = ctx.Clients.ToList(); Assert.Single(clients); var store = new ClientStore(ctx, NullLogger <ClientStore> .Instance); var client = await store.FindClientByIdAsync("MyClientId"); Assert.NotNull(client); Assert.Equal(1, client.AllowedScopes.Count); Assert.Equal(1, client.AllowedGrantTypes.Count); Assert.Equal(1, client.AllowedCorsOrigins.Count); Assert.Equal(1, client.Claims.Count); Assert.Equal(1, client.Properties.Count); Assert.Equal(1, client.RedirectUris.Count); } }
public async Task Adds_to_database() { var cmdletMock = CmdletMock.CreateMock(); var ctxName = Guid.NewGuid().ToString(); var newApiResource = new Models.ApiResource { Name = "MyResource", Scopes = new Models.Scope[] { new Models.Scope { Name = "Scope1" }, new Models.Scope { Name = "Scope2" } } }; using (var ctx = _dbContextFixture.GetContext(ctxName)) { var controller = new ApiResourceController(ctx, cmdletMock.Object); controller.AddApiResource(newApiResource, true); } using (var ctx = _dbContextFixture.GetContext(ctxName)) { var resources = ctx.ApiResources.ToList(); Assert.Single(resources); var store = new ResourceStore(ctx, NullLogger <ResourceStore> .Instance); var resource = await store.FindApiResourceAsync("MyResource"); Assert.NotNull(resource); Assert.Equal(2, resource.Scopes.Count); } cmdletMock.Verify(cmdlet => cmdlet.WriteObject(newApiResource), Times.Exactly(1)); }
public async Task Updates_in_database() { var ctxName = Guid.NewGuid().ToString(); var cmdletMock = CmdletMock.CreateMock(); var setClient = new Models.Client { ClientId = "MyClientId", AllowedScopes = new List <string> { "Scope1" }, AllowedCorsOrigins = new List <string> { "Origin1" }, AllowedGrantTypes = new List <string> { "GrantType1" }, Claims = new List <Claim> { new Claim("ClaimType1", "Claim1"), }, Properties = new Dictionary <string, string> { { "Key1", "Value1" } }, RedirectUris = new List <string> { "Redirect1" } }; using (var ctx = _dbContextFixture.GetContext(ctxName)) { ctx.Clients.Add(setClient.ToEntity()); ctx.SaveChanges(); } setClient.AllowedScopes = new List <string> { "Scope1", "Scope2" }; setClient.AllowedCorsOrigins = new List <string>(); setClient.AllowedGrantTypes = new List <string> { "GrantType1", "GrantType2" }; setClient.Claims.Add(new Claim("ClaimType2", "Claim2")); setClient.Properties.Add("Key2", "Value2"); setClient.RedirectUris = new List <string> { "Redirect2", "Redirect1" }; using (var ctx = _dbContextFixture.GetContext(ctxName)) { var controller = new ClientController(ctx, cmdletMock.Object); controller.UpdateClient(setClient, "MyNewClientId", true); } using (var ctx = _dbContextFixture.GetContext(ctxName)) { var store = new ClientStore(ctx, NullLogger <ClientStore> .Instance); var client = await store.FindClientByIdAsync("MyNewClientId"); Assert.NotNull(client); Assert.Equal(2, client.AllowedScopes.Count); Assert.Equal(0, client.AllowedCorsOrigins.Count); Assert.Equal(2, client.AllowedGrantTypes.Count); Assert.Equal(2, client.Claims.Count); Assert.Equal(2, client.Properties.Count); Assert.Equal(2, client.RedirectUris.Count); } cmdletMock.Verify(cmdlet => cmdlet.WriteObject(setClient), Times.Exactly(1)); }