public async Task DeleteDashboard()
        {
            int id;

            using (var context = await ContextFactory.CreateDbContext())
            {
                context.Dashboards.AddRange(DashboardFactory.GetFactory().Generate());
                context.SaveChanges();

                id = context.Dashboards.First().Id;
            }

            var response1 = await Controller.DeleteDashboard(id);

            CustomAssert.AssertStatusCodeResult <NoContentResult>(response1, 204);
            Assert.ThrowsAsync <shared.NotFoundException>(async() => await Controller.GetDashboard(id));
        }
        public async Task UpdateDashboard()
        {
            int id;
            var overrides = new Dictionary <string, object>
            {
                { "Title", "Dashboard" },
                { "OwnerTypeId", 1 },
                { "DashboardConfig", "Some dash config" }
            };
            var updatedValues = new Dictionary <string, object>
            {
                { "Title", "Updated title" },
                { "OwnerTypeId", 2 },
                { "DashboardConfig", "Updated Dash Config" }
            };

            using (var context = await ContextFactory.CreateDbContext())
            {
                context.Dashboards.AddRange(DashboardFactory.GetFactory(overrides).Generate());
                context.SaveChanges();

                id = context.Dashboards.First().Id;
            }

            var response1 = await Controller.UpdateDashboard(new Dashboard
            {
                Id              = id,
                Title           = updatedValues["Title"] as string,
                OwnerTypeId     = (int)updatedValues["OwnerTypeId"],
                DashboardConfig = updatedValues["DashboardConfig"] as string
            });

            var response2 = await Controller.GetDashboard(id);

            var result1 = CustomAssert.AssertOkResponse(response1);

            Assert.AreEqual(result1.Title, updatedValues["Title"] as string);
            Assert.AreEqual(result1.OwnerTypeId, (int)updatedValues["OwnerTypeId"]);
            Assert.AreEqual(result1.DashboardConfig, updatedValues["DashboardConfig"] as string);

            var result2 = CustomAssert.AssertOkResponse(response2);

            Assert.AreEqual(result2.Title, updatedValues["Title"] as string);
            Assert.AreEqual(result2.OwnerTypeId, (int)updatedValues["OwnerTypeId"]);
            Assert.AreEqual(result2.DashboardConfig, updatedValues["DashboardConfig"] as string);
        }
        public async Task SkipTakeDashboards(int resultCount, int skip, int take)
        {
            var expectedCount = Math.Min(resultCount - skip, take);

            expectedCount = expectedCount < 0 ? 0 : expectedCount;
            int?id;
            var userContext = new UserContext()
            {
                UserId = 1
            };
            var currentUserContext = A.Fake <ICurrentUserContext>();

            A.CallTo(() => currentUserContext.Get()).Returns(userContext);

            var controller = new DashboardController(Service, Mapper, currentUserContext, OwnerTypeService);

            using (var context = await ContextFactory.CreateDbContext())
            {
                context.Dashboards.AddRange(DashboardFactory
                                            .GetFactory(new Dictionary <string, object> {
                    { "OwnerTypeId", 1 }, { "OwnerId", userContext.UserId }
                }).Generate(resultCount));
                context.SaveChanges();

                id = context.Dashboards.Skip(skip).FirstOrDefault()?.Id;
            }



            var response =
                await controller.Search(new SearchQueryDashboard { Skip = skip, Take = take });

            var result = CustomAssert.AssertOkResponseCount(response, expectedCount);

            if (id.HasValue)
            {
                Assert.AreEqual(result.First().Id, id.Value);
            }
            else
            {
                Assert.AreEqual(result.Count, 0);
            }
        }
        public async Task <IActionResult> Get()
        {
            var factory = new DashboardFactory();

            return(Ok(factory.Dashboard()));
        }