コード例 #1
0
        // Test DELETE for Reference
        public void ReferencesController_Delete_ReturnsNoContentResult_WhenDeleted()
        {
            //Arrange
            int Id = 1;

            //Act
            var result           = controller.Delete(Id);
            var getDeletedResult = controller.Get(Id);

            //Assert
            Assert.IsType <NoContentResult>(result);
            Assert.IsType <NotFoundResult>(getDeletedResult);
        }
コード例 #2
0
        public async Task CanDeleteReference()
        {
            GetInMemoryDb(out SqliteConnection connection, out DbContextOptions <ReferencesDbContext> options);
            using (var index = new Index(true, true))
            {
                try
                {
                    var id = Guid.NewGuid();
                    using (var context = new ReferencesDbContext(options))
                    {
                        var service = new ReferencesController(context, index);
                        var result  = await service.Post(new Reference { Id = id }).ConfigureAwait(false);
                    }

                    // Use a separate instance of the context to verify correct data was saved to database
                    using (var context = new ReferencesDbContext(options))
                    {
                        var service = new ReferencesController(context, index);
                        var result  = await service.Get(id).ConfigureAwait(false);

                        Assert.Equal(id, result.Value.Id);
                        service.Delete(id);

                        var all = await service.GetAll(0, 10).ConfigureAwait(false);

                        Assert.Empty(all.ToArray());
                    }
                }
                finally
                {
                    connection.Close();
                }
            }
        }
コード例 #3
0
        public async Task CanDeleteReferenceAfterDeletingUsages()
        {
            GetInMemoryDb(out SqliteConnection connection, out DbContextOptions <ReferencesDbContext> options);

            using (var index = new Index(true, true))
            {
                try
                {
                    var id = Guid.NewGuid();
                    using (var context = new ReferencesDbContext(options))
                    {
                        var service = new ReferencesController(context, index);
                        var result  = await service.Post(new Reference
                        {
                            Id             = id,
                            ReferenceUsage = new List <ReferenceUsage> {
                                new ReferenceUsage {
                                    ApplicationId = 1, UserId = new Guid()
                                }
                            }
                        }).ConfigureAwait(false);
                    }

                    // Use a separate instance of the context to verify correct data was saved to database
                    using (var context = new ReferencesDbContext(options))
                    {
                        var service = new ReferencesController(context, index);
                        var result  = await service.Get(id).ConfigureAwait(false);

                        Assert.Equal(id, result.Value.Id);

                        Assert.Throws <InvalidOperationException>(() => service.Delete(id));

                        var all = await service.GetAll(0, 10).ConfigureAwait(false);

                        Assert.Single(all.ToArray());
                    }
                }
                finally
                {
                    connection.Close();
                }
            }
        }