Beispiel #1
0
        public void Build_with_valid_model_should_create_comment()
        {
            //given
            _commentRepository.Setup(x => x.Create(It.IsAny <Comment>()))
            .Returns(true);

            var dbItem = new DbItem("Article")
            {
            };

            dbItem.Add(new DbField("Comments"));
            Db db = new Db()
            {
                dbItem
            };
            Item article = db.GetItem("/sitecore/content/article");

            _context.Setup(x => x.GetItem <Item>(It.IsAny <Guid>(), false, false))
            .Returns(article);
            //when
            var result = _commentModelBuilder.Build(new CommentViewModel());

            //then
            result.Should().BeTrue();
        }
Beispiel #2
0
        public void Build_GivenPeople_ShouldFetchFavouritesByGivenPeople()
        {
            //Arrange
            const int id = 1;

            ;
            var people = new People {
                Name = "Test 1", Id = id
            };
            var favourites = new[]
            {
                new Favourite {
                    Id = 1, PeopleId = 1, People = people
                },
                new Favourite {
                    Id = 2, PeopleId = 2, People = new People {
                        Id = 2, Name = "sample"
                    }
                }
            };

            _mockFavouritesRepository.Setup(x => x.Matches(It.IsAny <Criteria <Favourite> >()))
            .Returns(favourites.Where(y => y.People.Name == people.Name).AsQueryable());
            const int expectedCount = 1;

            //Act
            var actualFavourites = _favouritesBuilder.Build(people).ToList();

            //Assert
            Assert.Equal(actualFavourites.Count, expectedCount);
            Assert.Equal(actualFavourites.Single().Id, id);
        }
        public IRate Calculate(TimeSlot timeSlot)
        {
            var refDatas = _refDataBuilder.Build(EarlyBirdRate).ToList();

            if (!refDatas.Any())
            {
                return(GetRate(timeSlot, 0));
            }

            var refData = refDatas.FirstOrDefault();

            if (refData.RefDataType.DaysAllowed == DaysAllowed.Weekdays && !timeSlot.EntryTime.IsWeekday())
            {
                return(GetRate(timeSlot, 0));
            }

            if (timeSlot.EntryTime >= new DateTime(timeSlot.EntryTime.Year, timeSlot.EntryTime.Month, timeSlot.EntryTime.Day, refData.RefDataType.EntryStartHours, refData.RefDataType.EntryStartMinutes, 0) &&
                timeSlot.EntryTime <= new DateTime(timeSlot.EntryTime.Year, timeSlot.EntryTime.Month, timeSlot.EntryTime.Day, refData.RefDataType.EntryEndHours, refData.RefDataType.EntryEndMinutes, 0) &&
                timeSlot.ExitTime >= new DateTime(timeSlot.ExitTime.Year, timeSlot.ExitTime.Month, timeSlot.ExitTime.Day, refData.RefDataType.ExitStartHours, refData.RefDataType.ExitStartMinutes, 0) &&
                timeSlot.ExitTime <= new DateTime(timeSlot.ExitTime.Year, timeSlot.ExitTime.Month, timeSlot.ExitTime.Day, refData.RefDataType.ExitEndHours, refData.RefDataType.ExitEndMinutes, 0))
            {
                return(GetRate(timeSlot, refData?.Amount ?? 0));
            }

            return(GetRate(timeSlot, 0));
        }
        public async Task <string> GenerateAsync(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            var fileName = _fileNameService.GetFilename(reportServiceContext, FileName, OutputTypes.Excel);

            var reportData = await _reportDataProvider.ProvideAsync(reportServiceContext, cancellationToken);

            using (var workbook = _excelFileService.NewWorkbook())
            {
                workbook.Worksheets.Clear();
                var summaries        = new List <ISummaryRow>();
                var summaryWorksheet = _excelFileService.GetWorksheetFromWorkbook(workbook, SummaryName);

                foreach (var worksheetTask in reportServiceContext.Tasks)
                {
                    var worksheet = _worksheets.GetValueOrDefault(worksheetTask);

                    summaries.Add(worksheet.Generate(workbook, reportServiceContext, reportData, cancellationToken));
                }

                var summaryModel = _summaryPageModelBuilder.Build(reportServiceContext, reportData);
                summaryModel.SummaryRows = summaries;

                _summarPageRenderService.Render(summaryModel, summaryWorksheet);

                await _excelFileService.SaveWorkbookAsync(workbook, fileName, reportServiceContext.Container, cancellationToken);
            }

            return(fileName);
        }
Beispiel #5
0
        public async Task <IEnumerable <string> > GenerateAsync(IReportServiceContext reportServiceContext, IReportServiceDependentData reportsDependentData, CancellationToken cancellationToken)
        {
            var fileName = _fileNameService.GetFilename(reportServiceContext, ReportName, OutputTypes.Excel);

            var reportsToBeGenerated = _frmReports.Where(x => reportServiceContext.Tasks.Contains(x.TaskName, StringComparer.OrdinalIgnoreCase));

            using (var workbook = _excelService.NewWorkbook())
            {
                workbook.Worksheets.Clear();
                List <IFrmSummary> rows = new List <IFrmSummary>();
                var summaryWorksheet    = _excelService.GetWorksheetFromWorkbook(workbook, SummaryName);

                foreach (var frmReport in reportsToBeGenerated)
                {
                    rows.Add(frmReport.Generate(workbook, reportServiceContext, reportsDependentData, cancellationToken));
                }

                var frmSummaryReport = _frmSummaryReportModelBuilder.Build(reportServiceContext, reportsDependentData);
                frmSummaryReport.SummaryTable = rows;
                _frmSummaryReportRenderService.Render(frmSummaryReport, summaryWorksheet);

                await _excelService.SaveWorkbookAsync(workbook, fileName, reportServiceContext.Container, cancellationToken);
            }

            return(new[] { fileName });
        }
Beispiel #6
0
        public async Task <IEnumerable <string> > GenerateAsync(
            IReportServiceContext reportServiceContext,
            IReportServiceDependentData reportsDependentData,
            CancellationToken cancellationToken)
        {
            var fundingSummaryReportModel = _devolvedFundingSummaryReportBuilder.Build(reportServiceContext, reportsDependentData);

            var fileName = _fileNameService.GetFilename(reportServiceContext, ReportName, OutputTypes.Excel);

            using (var workbook = _excelService.NewWorkbook())
            {
                workbook.Worksheets.Clear();

                foreach (var reportModel in fundingSummaryReportModel)
                {
                    var worksheet = _excelService.GetWorksheetFromWorkbook(workbook, reportModel.SofLookup.SofCode);

                    _devolvedFundingSummaryReportRenderService.Render(reportModel, worksheet);
                }

                await _excelService.SaveWorkbookAsync(workbook, fileName, reportServiceContext.Container, cancellationToken);
            }

            return(new[] { fileName });
        }
Beispiel #7
0
        public ActionResult Details(CommentViewModel commentViewModel)
        {
            _commenModelBuilder.Build(commentViewModel);
            var article = _repository.Get(commentViewModel.ArticleId);

            return(View(article));
        }
Beispiel #8
0
        protected override object ProcessDbCommand(SqlCommand dbCommand)
        {
            SpExecResult result = new SpExecResult();

            SqlDataReader reader = null;

            try
            {
                // set stored procedure name
                result.StoredProcedureName = DbContext.GetFullStoredProcName(GetCommandText());

                // execute the stored procedure
                Stopwatch sw = Stopwatch.StartNew();
                reader = dbCommand.ExecuteReader();
                sw.Stop();
                TimeSpan ts = sw.Elapsed;

                // Format and display the TimeSpan value.
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                   ts.Hours, ts.Minutes, ts.Seconds,
                                                   ts.Milliseconds / 10);
                Console.WriteLine($"response to DB: {elapsedTime}");
                if (!reader.HasRows)
                {
                    // if the stored procedure did not
                    // return any row
                    reader.Close();
                    result.ReturnCode = OutReturnCode;
                    return(result);
                }

                IModelBuilder <TResult> builder = CreateBuilder();

                while (reader.Read())
                {
                    TResult newModel = builder.Build(reader);
                    result.AppendRow(newModel);
                }

                // close the reader
                reader.Close();

                // set return code
                result.ReturnCode = OutReturnCode;
                return(result);
            }
            catch (Exception e)
            {
                throw;
            }
            finally
            {
                if ((reader != null) && !reader.IsClosed)
                {
                    // close the data reader if it was not closed
                    reader.Close();
                }
            }
        }
Beispiel #9
0
        public void Get_GivenPeopleName_ShouldGetThePeople()
        {
            //Arrange

            var people = new People {
                Name = "Test 1", Id = 1
            };

            _mockRepository.Setup(x => x.Get(It.IsAny <Criteria <People> >())).Returns(people);

            //Act
            var actualPeople = _peopleBuilder.Build(people.Name);

            //Assert
            Assert.True(actualPeople.Name == people.Name);
            _mockRepository.Verify(x => x.Get(It.IsAny <Criteria <People> >()), Times.Once);
        }
Beispiel #10
0
        public IRate Calculate(TimeSlot timeSlot)
        {
            var duration = CalculateDuration(timeSlot);
            var refDatas = _refDataBuilder.Build("Standard Rate").ToList();
            var refData  = refDatas.Where(x => x.Duration == duration || duration > x.Duration).OrderByDescending(x => x.Duration).FirstOrDefault();

            return(GetRate(timeSlot, refData?.Amount ?? 0));
        }
Beispiel #11
0
        public IActionResult Get(int peopleId)
        {
            var people = new People {
                Id = peopleId
            };
            var favourites = _favouritesBuilder.Build(people).ToList();

            return(Ok(favourites));
        }
        public async Task <IEnumerable <string> > GenerateAsync(IOperationsReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            var ilrFileSubmissionsPerDayModel = await _modelBuilder.Build(reportServiceContext, cancellationToken);

            var reportFileName = _fileNameService.Generate(reportServiceContext, ReportName, OutputTypes.Excel, true, true, false);

            await GenerateWorkBookAsync(ilrFileSubmissionsPerDayModel, TemplateName, ReportDataSource, reportServiceContext, reportFileName, cancellationToken);

            return(new[] { reportFileName });
        }
        public async Task <IEnumerable <string> > GenerateAsync(IReportServiceContext reportServiceContext, IReportServiceDependentData reportsDependentData, CancellationToken cancellationToken)
        {
            var fileName = _fileNameService.GetFilename(reportServiceContext, ReportName, OutputTypes.Csv);

            var model = _modelBuilder.Build(reportServiceContext, reportsDependentData);

            await _csvService.WriteAsync <TModel, TClassMap>(model, fileName, reportServiceContext.Container, cancellationToken);

            return(new[] { fileName });
        }
Beispiel #14
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            var listTypeBuilder = EngineContext.Current.Resolve <ITypeFinder>().FindClassesOfType <IModelBuilder>();

            foreach (Type typeBuilder in listTypeBuilder)
            {
                IModelBuilder builder = (IModelBuilder)Activator.CreateInstance(typeBuilder, modelBuilder);
                builder.Build();
            }
            base.OnModelCreating(modelBuilder);
        }
Beispiel #15
0
        public RoutesModel Execute(RouteRequestModel request)
        {
            var model = _routeBuilder.Build();

            model.Filter = new JsonGridFilter
            {
                ColumnName = request.Column,
                Values     = new[] { request.Value }
            };

            return(model);
        }
Beispiel #16
0
 public IActionResult Login(Data.Models.People request)
 {
     try
     {
         var people = _peopleBuilder.Build(request.Name);
         return(Ok(people));
     }
     catch (InvalidDataException)
     {
         return(Unauthorized());
     }
 }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IModelBuilder modelBuilder)
        {
            modelBuilder.Build();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors(MyAllowSpecificOrigins);
            app.UseRouting();
            app.UseRestfulObjects();
        }
        protected override async Task <object> ProcessDbCommandAsync(SqlCommand dbCommand)
        {
            SpExecResult result = new SpExecResult();

            SqlDataReader reader = null;

            try
            {
                // set stored procedure name
                result.StoredProcedureName = DbContext.GetFullStoredProcName(GetCommandText());

                // execute the stored procedure
                reader = await dbCommand.ExecuteReaderAsync();

                if (!reader.HasRows)
                {
                    // if the stored procedure did not
                    // return any row
                    reader.Close();
                    result.ReturnCode = OutReturnCode;
                    return(result);
                }

                IModelBuilder <TResult> builder = CreateBuilder();

                while (await reader.ReadAsync())
                {
                    TResult newModel = builder.Build(reader);
                    result.AppendRow(newModel);
                }

                // close the reader
                reader.Close();

                // set return code
                result.ReturnCode = OutReturnCode;
                return(result);
            }
            catch (Exception e)
            {
                throw;
            }
            finally
            {
                if ((reader != null) && !reader.IsClosed)
                {
                    // close the data reader if it was not closed
                    reader.Close();
                }
            }
        }
Beispiel #19
0
        private IList <UserReviewViewModel> BuildUserReviews(IList <UserReviewDM> items)
        {
            IList <UserReviewViewModel> results = new List <UserReviewViewModel>();

            if (items != null && items.Count > 0)
            {
                foreach (UserReviewDM userReviewDomainModel in items)
                {
                    results.Add(_userReviewViewModelBuilder.Build(userReviewDomainModel));
                }
            }

            return(results);
        }
        public IRate Calculate(TimeSlot timeSlot)
        {
            var duration = CalculateDuration(timeSlot);
            var refDatas = _refDataBuilder.Build("Standard Rate").ToList();

            if (!refDatas.Any())
            {
                return(GetRate(timeSlot, 0));
            }
            var refData        = refDatas.Where(x => x.Duration == duration || duration > x.Duration).OrderByDescending(x => x.Duration).FirstOrDefault();
            var durationInDays = Math.Ceiling(Convert.ToDecimal((timeSlot.ExitTime - timeSlot.EntryTime).TotalDays));

            return(GetRate(timeSlot, (refData?.Amount * durationInDays) ?? 0));
        }
        public async Task <IEnumerable <string> > GenerateExcelAsync(IReportServiceContext reportServiceContext, IReportServiceDependentData reportsDependentData, CancellationToken cancellationToken, int?fisInfoRowIndexToDelete = null)
        {
            var model = _modelBuilder.Build(reportServiceContext, reportsDependentData);

            return(new[]
            {
                await WriteWorkbookAsync(
                    reportServiceContext,
                    model,
                    TemplateFileName,
                    DataSource,
                    fisInfoRowIndexToDelete,
                    cancellationToken)
            });
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IModelBuilder builder, ILoggerFactory loggerFactory)
        {
            // for Demo use Log4Net. Configured in log4net.config
            loggerFactory.AddLog4Net();

            builder.Build();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors(MyAllowSpecificOrigins);
            app.UseRouting();
            app.UseRestfulObjects();
        }
        public virtual ISummaryRow Generate(Workbook workbook, IReportServiceContext reportServiceContext, IReportData reportData, CancellationToken cancellationToken)
        {
            var fundingReportMonitoringModels = _fundingRuleMonitoringReportModelBuilder.Build(reportServiceContext, reportData).ToList();

            if (fundingReportMonitoringModels.Any())
            {
                var worksheet = _excelService.GetWorksheetFromWorkbook(workbook, _tabName);

                _fundingRuleMonitoringRenderService.Render(fundingReportMonitoringModels, worksheet);
            }

            return(new SummaryRow
            {
                Report = _tabName,
                Title = _title,
                NumberOfQueries = fundingReportMonitoringModels.Count
            });
        }
Beispiel #24
0
        public async Task <IEnumerable <string> > GenerateAsync(IOperationsReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            var validationRuleDetails = await _modelBuilder.Build(reportServiceContext, cancellationToken);

            var fileNameCsv  = _fileNameService.Generate(reportServiceContext, ReportName, OutputTypes.Csv, false, false, includeJobId: true);
            var fileNameJson = _fileNameService.Generate(reportServiceContext, ReportName, OutputTypes.Json, false, false, includeJobId: true);

            var validationRuleDetailsList = validationRuleDetails.ToList();

            using (var stream = await _fileService.OpenWriteStreamAsync(fileNameJson, reportServiceContext.Container, cancellationToken))
            {
                _serializationService.Serialize(validationRuleDetailsList, stream);
            }

            await _csvFileService.WriteAsync <ValidationRuleDetail, ValidationRuleDetailReportClassMap>(validationRuleDetailsList, fileNameCsv, reportServiceContext.Container, cancellationToken);

            return(new[] { fileNameCsv });
        }
Beispiel #25
0
        private TModel HydrateDestinationObject <TModel>(string fileName, string sheetName,
                                                         IDictionary <string, CellToPropertyMap> mappings, IDataSheetRow rowToMap)
            where TModel : class
        {
            var destinationObject = _modelBuilder.Build <TModel>();

            foreach (var cellToPropertyMapping in mappings)
            {
                var mapping        = cellToPropertyMapping.Value;
                var cell           = rowToMap.Cell(mapping.CellColumn);
                var convertedValue = _valueConverter.ConvertTo(cell, mapping.Property.PropertyType);
                mapping.Property.SetValue(destinationObject, convertedValue);
                destinationObject = AddPropertyMetadataIfPossible(mapping.Property, fileName, sheetName, cell,
                                                                  destinationObject);
            }

            return(destinationObject);
        }
Beispiel #26
0
        public IRate Calculate(TimeSlot timeSlot)
        {
            if (!timeSlot.EntryTime.IsWeekday())
            {
                return(GetRate(timeSlot, 0));
            }

            if (timeSlot.EntryTime >= new DateTime(timeSlot.EntryTime.Year, timeSlot.EntryTime.Month, timeSlot.EntryTime.Day, 6, 0, 0) &&
                timeSlot.EntryTime <= new DateTime(timeSlot.EntryTime.Year, timeSlot.EntryTime.Month, timeSlot.EntryTime.Day, 9, 0, 0) &&
                timeSlot.ExitTime >= new DateTime(timeSlot.ExitTime.Year, timeSlot.ExitTime.Month, timeSlot.ExitTime.Day, 15, 30, 0) &&
                timeSlot.ExitTime <= new DateTime(timeSlot.ExitTime.Year, timeSlot.ExitTime.Month, timeSlot.ExitTime.Day, 23, 30, 0))
            {
                var refDatas = _refDataBuilder.Build("Early Bird Rate").ToList();
                var refData  = refDatas.FirstOrDefault();
                return(GetRate(timeSlot, refData?.Amount ?? 0));
            }

            return(GetRate(timeSlot, 0));
        }
Beispiel #27
0
        private static void Create <T>(MainDbContext context, DbSet <T> dbSet, IModelBuilder <T> modelBuilder) where T : class
        {
            var list = modelBuilder.Build();

            foreach (var oneList in list.SplitInToParts(1))
            {
                Console.WriteLine();
                Console.Write("Save in DB - ");

                foreach (var item in oneList)
                {
                    dbSet.Add(item);
                }

                var erros = context.GetValidationErrors();

                context.SaveChanges();

                Console.Write("save successful");
            }
        }
Beispiel #28
0
 public RoutesModel Execute(DefaultRouteRequestModel request)
 {
     return(_routeBuilder.Build());
 }