Esempio n. 1
0
        public static ReturnObject UpdateLayout(HttpContext context, int containerId, string[] widget)
        {
            IWidgetRepository widgetRepo = new WidgetRepository(ConfigurationManager.ConnectionStrings["FDARems"].ConnectionString);

            Framework.Security.User user = Framework.Security.Manager.GetUser();
            WidgetSettings settings = widgetRepo.FindSettingsByUserId(user.ID ?? 0);

            if(containerId == 1)
                settings.Column1 = widget.Aggregate((i,j) => i+"|"+j);
            else
                settings.Column2 = widget.Aggregate((i,j) => i+"|"+j);

            widgetRepo.Save(settings);

            return new ReturnObject()
            {
                Growl = new ReturnGrowlObject()
                {
                    Type = "default",
                    Vars = new ReturnGrowlVarsObject()
                    {
                        text = "Your changes have been saved.",
                        title = "Layout Saved"
                    }
                }
            };
        }
Esempio n. 2
0
 private async Task WidgetRepositoryFillerAsync(WidgetRepository widgetRepository, IEnumerable <Widget> widgets)
 {
     foreach (var widget in widgets)
     {
         await widgetRepository.AddAsync(widget);
     }
 }
Esempio n. 3
0
        // GET: Home
        public ActionResult Index()
        {
            var widgetRepository = new WidgetRepository();
            var widgetModel      = widgetRepository.GetWidgets();

            return(View(widgetModel));
        }
Esempio n. 4
0
        public async Task ReturnNullIfNotExists()
        {
            var widget = await WidgetFactory.GetExisting();

            var responseWidget = await WidgetRepository.Get(Guid.NewGuid());

            Assert.Null(responseWidget);
        }
        public async Task PopulateUpdatedBy()
        {
            var widget = await WidgetFactory.GetExisting();

            var response = await WidgetRepository.Update(widget);

            Assert.Equal(AuthContext.UserName, response.UpdatedBy);
        }
Esempio n. 6
0
        public async Task ReturnEntityIfExists()
        {
            var widget = await WidgetFactory.GetExisting();

            var responseWidget = await WidgetRepository.Get(widget.Id);

            Assert.Equal(widget, responseWidget);
        }
        public async Task NotPopulateCreatedDate()
        {
            var widget = await WidgetFactory.GetExisting();

            var originalCreatedDate = widget.CreatedDate;
            var response            = await WidgetRepository.Update(widget);

            Assert.Equal(originalCreatedDate, response.CreatedDate);
        }
        public async Task ReturnEmptyListIfNoneExists()
        {
            DataContext.Widgets.RemoveRange(DataContext.Widgets);
            await DataContext.SaveChangesAsync();

            var responseWidgets = await WidgetRepository.List();

            Assert.Empty(responseWidgets);
        }
Esempio n. 9
0
        public async Task RemoveRecordFromDatabase()
        {
            var widget = await WidgetFactory.GetExisting();

            await WidgetRepository.Delete(widget.Id);

            var dbWidget = await DataContext.Widgets.FindAsync(widget.Id);

            Assert.Null(dbWidget);
        }
        public async Task UpdateRecordInDatabase()
        {
            var expectedName = Guid.NewGuid().ToString();
            var widget       = await WidgetFactory.GetExisting();

            widget.Name = expectedName;
            var response = await WidgetRepository.Update(widget);

            Assert.Equal(expectedName, response.Name);
        }
Esempio n. 11
0
        public async Task EquipmentVisualization_notFound()
        {
            var repository = new WidgetRepository(_options, new HttpClient());
            var controller = new WidgetsController(repository, _mapper, _logger);

            var result = await controller.EquipmentVisualization(-1);

            result.Should().NotBeNull();
            var okResult = result.Should().BeOfType <NotFoundResult>().Subject;

            Assert.True(okResult.StatusCode.Equals(404));
        }
        public async Task NotReturnForOtherUser()
        {
            var count             = 4;
            var unexpectedWidgets = new List <Widget>();

            for (int i = 0; i < count; i++)
            {
                unexpectedWidgets.Add(await SecondaryWidgetFactory.GetExisting());
            }

            var responseWidgets = await WidgetRepository.List();

            Assert.All(unexpectedWidgets, unexpectedWidget => Assert.DoesNotContain(responseWidgets, responseWidget => unexpectedWidget.Id == responseWidget.Id));
        }
        public async Task ReturnAll()
        {
            var count           = 4;
            var expectedWidgets = new List <Widget>();

            for (int i = 0; i < count; i++)
            {
                expectedWidgets.Add(await WidgetFactory.GetExisting());
            }

            var responseWidgets = await WidgetRepository.List();

            Assert.All(expectedWidgets, expectedWidget => Assert.Contains(responseWidgets, responseWidget => expectedWidget.Id == responseWidget.Id));
        }
Esempio n. 14
0
        public async void AddAsyncShouldAddWidget()
        {
            var options = OverwatchOptionBuilder.CreateBuilderWithName("OverwatchDbAddWidgetsAsync");

            using (var overwatchContext = new OverwatchContext(options))
            {
                var widgetRepository = new WidgetRepository(overwatchContext);
                await WidgetRepositoryFillerAsync(widgetRepository, _widgets);

                var result = await widgetRepository.GetAllAsync();

                Assert.Equal(result.Count(), _widgets.Count());
            }
        }
Esempio n. 15
0
        public async void DeleteByIdAsyncShouldDeleteCorrectWidget()
        {
            var options = OverwatchOptionBuilder.CreateBuilderWithName("OverwatchDbDeleteByIdAsync");

            using (var overwatchContext = new OverwatchContext(options))
            {
                var    widgetRepository = new WidgetRepository(overwatchContext);
                Widget widgetToDelete   = _widgets.First();
                await widgetRepository.AddAsync(widgetToDelete);

                var result = await widgetRepository.DeleteByIdAsync(widgetToDelete.Id);

                Assert.Equal(1, result);
            }
        }
Esempio n. 16
0
        public async void GetByIdAsyncShouldReturnCorrectWidget()
        {
            var options = OverwatchOptionBuilder.CreateBuilderWithName("OverwatchDbGetWidgetByIdAsync");

            using (var overwatchContext = new OverwatchContext(options))
            {
                var    widgetRepository = new WidgetRepository(overwatchContext);
                Widget widgetToFind     = _widgets.First();
                await widgetRepository.AddAsync(widgetToFind);

                var result = await widgetRepository.GetByIdAsync(widgetToFind.Id);

                Assert.Equal(widgetToFind, result);
            }
        }
Esempio n. 17
0
        public async Task EquipmentVisualization_okResult()
        {
            var repository = new WidgetRepository(_options, new HttpClient());
            var controller = new WidgetsController(repository, _mapper, _logger);

            var result = await controller.EquipmentVisualization(12);

            result.Should().NotBeNull();
            var okResult = result.Should().BeOfType <OkObjectResult>().Subject;

            Assert.True(okResult.StatusCode.Equals(200));
            var model = okResult.Value.Should().BeAssignableTo <WidgetResponse>().Subject;

            Assert.False(model.DefaultCss.Equals(null));
            Assert.True(model.Code.Length > 0);
        }
Esempio n. 18
0
        public async void PutAsyncShouldEditCorrectWidget()
        {
            var options = OverwatchOptionBuilder.CreateBuilderWithName("OverwatchDbPutWidgetAsync");

            using (var overwatchContext = new OverwatchContext(options))
            {
                var widgetRepository = new WidgetRepository(overwatchContext);
                await WidgetRepositoryFillerAsync(widgetRepository, _widgets);

                Widget widgetToEdit = _widgets.First();
                widgetToEdit.Color = "Green";
                var result = await widgetRepository.PutAsync(widgetToEdit.Id, widgetToEdit);

                Assert.Equal(1, result);
                var returnedWidget = widgetRepository.GetByIdAsync(widgetToEdit.Id).Result;
                Assert.Equal(returnedWidget, widgetToEdit);
            }
        }
        public WidgetServicio()
        {
            widgetsRepository       = new WidgetRepository();
            _widgetsList            = new List <P2PWidget>();
            _widgetsListByContainer = new List <P2PWidget>();
            P2PWidget widget1 = widgetsRepository.AddWidget(1, 2, "y", "{test : 1}", 1, "Donation", true, "y", "n");
            P2PWidget widget2 = widgetsRepository.AddWidget(2, 9, "y", "{test : 2}", 1, "Event", false, "y", "n");
            P2PWidget widget3 = widgetsRepository.AddWidget(3, 10, "n", "{test : 3}", 1, "Donation", false, "y", "y");
            P2PWidget widget4 = widgetsRepository.AddWidget(4, 8, "y", "{test : 4}", 1, "Event", true, "y", "n");
            P2PWidget widget5 = widgetsRepository.AddWidget(5, 2, "n", "{test : 5}", 1, "DonationThankYou", true, "y", "n");

            _widgetsList.Add(widget1);
            _widgetsList.Add(widget2);
            _widgetsList.Add(widget3);
            _widgetsList.Add(widget4);
            _widgetsList.Add(widget5);
            _widgetsListByContainer.Add(widget1);
            _widgetsListByContainer.Add(widget5);
        }
Esempio n. 20
0
        public FleetControllerTest()
        {
            this.CreateAppContext();

            // Automapper initializers
            Mapper.AddProfile <FleetMappingProfile>();
            Mapper.AddProfile <WidgetMappingProfile>();

            // setting up the context and repositories
            this.FleetDbContext = this.CreateDbContext <FleetDbContext>();
            FleetRepository      fleetRepository = new FleetRepository(this.FleetDbContext);
            FleetDomain          fleetDomain     = new FleetDomain(fleetRepository);
            FleetDashboardDomain dashboardDomain = new FleetDashboardDomain(fleetRepository);

            this.WidgetDbContext = this.CreateDbContext <WidgetDbContext>();
            WidgetRepository widgetRepository = new WidgetRepository(this.WidgetDbContext);
            WidgetDomain     widgetDomain     = new WidgetDomain(widgetRepository);

            this.Controller = new FleetController(fleetDomain, dashboardDomain, widgetDomain);
        }
Esempio n. 21
0
        public QuarryControllerTest()
        {
            this.CreateAppContext();

            // Automapper initializers
            Mapper.AddProfile<QuarryMappingProfile>();
            Mapper.AddProfile<WidgetMappingProfile>();

            // setting up the context and repositories
            this.QuarryDbContext = this.CreateDbContext<QuarryDbContext>();
            QuarryRepository quarryRepository = new QuarryRepository(this.QuarryDbContext);
            QuarryDomain quarryDomain = new QuarryDomain(quarryRepository);
            QuarryDashboardDomain dashboardDomain = new QuarryDashboardDomain(quarryRepository);

            this.WidgetDbContext = this.CreateDbContext<WidgetDbContext>();
            WidgetRepository widgetRepository = new WidgetRepository(this.WidgetDbContext);
            WidgetDomain widgetDomain = new WidgetDomain(widgetRepository);

            this.Controller = new QuarryController(quarryDomain, dashboardDomain, widgetDomain);
        }
Esempio n. 22
0
        public QuarryControllerTest()
        {
            this.CreateAppContext();

            // Automapper initializers
            Mapper.AddProfile <QuarryMappingProfile>();
            Mapper.AddProfile <WidgetMappingProfile>();

            // setting up the context and repositories
            this.QuarryDbContext = this.CreateDbContext <QuarryDbContext>();
            QuarryRepository      quarryRepository = new QuarryRepository(this.QuarryDbContext);
            QuarryDomain          quarryDomain     = new QuarryDomain(quarryRepository);
            QuarryDashboardDomain dashboardDomain  = new QuarryDashboardDomain(quarryRepository);

            this.WidgetDbContext = this.CreateDbContext <WidgetDbContext>();
            WidgetRepository widgetRepository = new WidgetRepository(this.WidgetDbContext);
            WidgetDomain     widgetDomain     = new WidgetDomain(widgetRepository);

            this.Controller = new QuarryController(quarryDomain, dashboardDomain, widgetDomain);
        }
Esempio n. 23
0
        public void PriceBreakdownById()
        {
            var httpClient       = new HttpClient(_handlerMock.Object);
            var subjectUnderTest = new WidgetRepository(_options, httpClient);
            var result           = subjectUnderTest.PriceBreakdownById(12, null);

            result.Should().NotBeNull(); // this is fluent assertions here...

            // also check the 'http' call was like we expected it
            var expectedUri = new Uri("https://serverTest.com/recipes/12/priceBreakdownWidget?123");

            _handlerMock.Protected().Verify(
                "SendAsync",
                Times.Exactly(2), // we expected a single external request
                ItExpr.Is <HttpRequestMessage>(req =>
                                               req.Method == HttpMethod.Get && // we expected a GET request
                                               req.RequestUri == expectedUri // to this uri
                                               ),
                ItExpr.IsAny <CancellationToken>()
                );
        }
Esempio n. 24
0
        protected async Task <IWidgetRepository> CreateWidgetRepository(
            Mock <IDatabaseConnectionFactory> connectionFactoryMock = null)
        {
            if (connectionFactoryMock == null)
            {
                var db = new InMemoryDatabase();
                db.OpenConnection();

                connectionFactoryMock = new Mock <IDatabaseConnectionFactory>();
                connectionFactoryMock.Setup(c => c.GetConnection()).Returns(db.OpenConnection());
            }

            IWidgetRepository widgetRepository = new WidgetRepository(connectionFactoryMock.Object);

            var projectRoot = AppContext.BaseDirectory.Substring(0,
                                                                 AppContext.BaseDirectory.LastIndexOf("bin", StringComparison.Ordinal));
            var script = File.ReadAllText(Path.Combine(projectRoot, XyzWidgetSchema));

            await widgetRepository.CreateSqliteSchema(script);

            return(widgetRepository);
        }
Esempio n. 25
0
 public WidgetQueryController()
 {
     _repo = new WidgetRepository();
 }
        public async Task PopulateIdField()
        {
            var widget   = WidgetFactory.GetNew();
            var response = await WidgetRepository.Insert(widget);

            Assert.NotEqual(default, response.Id);
 public WidgetMutationsController()
 {
     _repo = new WidgetRepository();
 }
Esempio n. 28
0
 public async Task ThrowExceptionIfNotExists()
 {
     await Assert.ThrowsAnyAsync <Exception>(async() => await WidgetRepository.Delete(Guid.NewGuid()));
 }
Esempio n. 29
0
        public async Task ThrowExceptionIfForOtherUser()
        {
            var widget = await SecondaryWidgetFactory.GetExisting();

            await Assert.ThrowsAsync <NotFoundException>(async() => await WidgetRepository.Delete(widget.Id));
        }
Esempio n. 30
0
 public WidgetDomain(WidgetRepository widgetRepository)
 {
     this.widgetRepository = widgetRepository;
 }
Esempio n. 31
0
 public WidgetParamRepository(AreaContext context)
 {
     _repository       = context.WidgetParam;
     _widgetRepository = new WidgetRepository(context);
 }
Esempio n. 32
0
 public WidgetDomain(WidgetRepository widgetRepository)
 {
     this.widgetRepository = widgetRepository;
 }