public bool ValidateRecord(string record)
        {
            bool result = true;

            string[] recordFields = record.Split(',');

            result = isDepartmentNameValid(recordFields[0]);
            if (result)
            {
                result = isCrewCodeValid(recordFields[1]);
            }
            if (result)
            {
                result = isEmployeeNameValid(recordFields[2]);
            }
            if (result)
            {
                result = isStatusValid(recordFields[3]);
            }
            if (result)
            {
                result = isEmployeeNumberValid(recordFields[4]);
            }
            if (result)
            {
                result = isRoleTypeValid(recordFields[5]);
            }
            if (result)
            {
                result = isSeniorityDateValid(recordFields[6]);
            }
            if (result)
            {
                result = isSupervisorNameValid(recordFields[7], recordFields[5]);
            }
            if (result)
            {
                result = isSupervisorNumberValid(recordFields[4], recordFields[8], recordFields[5]);
            }

            if (result)
            {
                DataFileRecordModel dataFileModel = CreateDataFileRecordModel(record);

                if (isDuplicatedRecord(recordFields[4]))
                {
                    DuplicatedRecords.Add(dataFileModel);
                }
                else
                {
                    ValidRecords.Add(dataFileModel);
                }
            }
            else
            {
                InvalidRecords.Add(record);
            }

            return(result);
        }
        public List <Employee> CreateEmployeesFromRecords(List <DataFileRecordModel> records)
        {
            List <Employee>   employees = new List <Employee>();
            List <Department> allDistinctDepartments = _dal.GetAllDistinctDepartments();
            List <RoleType>   allDistinctRoleTypes   = _dal.GetAllDistinctRollTypes();
            List <Crew>       allDistinctCrews       = _dal.GetAllDisctinctCrews();

            foreach (var record in records)
            {
                try
                {
                    Employee employee = new Employee()
                    {
                        name           = record.employee_name,
                        department_id  = allDistinctDepartments.Where(d => d.department_name == record.DepartmentName).SingleOrDefault().department_id,
                        employee_num   = record.Employee_num,
                        status         = (record.Status == Statuses.Active) ? (true) : (false),
                        seniority_date = Convert.ToDateTime(record.SeniorityDate),
                        roletype_id    = allDistinctRoleTypes.Where(r => r.roletype_name == record.Role).SingleOrDefault().roletype_id,
                        crew_id        = allDistinctCrews.Where(c => c.crew_code == record.Crew_Code).SingleOrDefault().crew_id,
                        supervisor_id  = _dal.GetEmployeeIdForEmployeeNumber(record.Supervisor_num)
                    };

                    employees.Add(employee);
                }
                catch
                {
                    // TODO: This needs to get fixed!
                    InvalidRecords.Add(record.ToString());
                }
            }

            return(employees);
        }
Ejemplo n.º 3
0
        public IEnumerable <Guid> GetInvalidRecords(Guid fileId)
        {
            if (InvalidRecords.ContainsKey(fileId))
            {
                return(InvalidRecords[fileId]);
            }

            return(new Guid[] { });
        }
        public void ValidateUnnassignedVariants(ConcurrentDictionary <string, List <Product> > unnassignedVariants)
        {
            if (unnassignedVariants.Count != 0)
            {
                foreach (var kvp in unnassignedVariants)
                {
                    var errors = new List <string>();
                    foreach (var variant in kvp.Value)
                    {
                        errors.Add($"Item {variant.Id} was added but parent {kvp.Key} was never added");
                    }

                    InvalidRecords.Add(kvp.Key, errors);
                }
            }
        }
        public void ValidateProduct(Product product)
        {
            var errors      = new List <string>();
            var priceErrors = ValidatePrices(product);

            errors.AddRange(priceErrors);

            if (string.IsNullOrWhiteSpace(product.ParentId) && product.Variants.Count == 0 && product.Prices.Count == 0)
            {
                errors.Add("Product has no parent, no variants and no price. A product must have a price or must be a parent with variants.");
            }

            if (errors.Count != 0)
            {
                InvalidRecords.Add(product.Id, errors);
            }
        }
Ejemplo n.º 6
0
        public OsdrTestHarness()
        {
            var builder = new ConfigurationBuilder()
                          .AddJsonFile("appsettings.bddtests.json", true, true);

            var configuration = builder.Build();

            var services = new ServiceCollection();

            JohnId = NewId.NextGuid();
            JaneId = NewId.NextGuid();

            var testHarnessSettings = configuration.GetSection("TestHarness").Get <TestHarnessSettings>();

            _harness             = new InMemoryTestHarness();
            _harness.TestTimeout = TimeSpan.FromSeconds(testHarnessSettings.Timeout);

            services.AddSingleton <IBlobStorage, InMemoryStorage>();

            services.AddOptions();

            services.AddSingleton <EventStore.InMemoryEventStore>();
            services.AddSingleton <IEventStore>(c => c.GetService <EventStore.InMemoryEventStore>());
            services.AddSingleton <EventStore.IEventStore>(c => c.GetService <EventStore.InMemoryEventStore>());
            services.AddScoped <IEventPublisher, CqrsLite.MassTransit.MassTransitEventPublisher>();
            services.AddScoped <ISession, Session>();
            services.AddScoped <IRepository, Repository>();
            services.AddScoped <IKeyValueRepository, InMemoryKeyValueRepository>();

            services.AddSingleton <IConsumerScopeProvider, DependencyInjectionConsumerScopeProvider>();

            services.Configure <Infrastructure.AccessControl.AccessControl>(configuration.GetSection("AccessControl"));
            services.AddSingleton <IAccessControl, Infrastructure.AccessControl.AppSettingsAccessControl>();

            services.AddSingleton(new MongoClient(Environment.ExpandEnvironmentVariables("%OSDR_MONGO_DB%")));
            services.AddScoped(service => service.GetService <MongoClient>().GetDatabase(MongoDatabaseName));

            var allAssembly = new Assembly[]
            {
                Assembly.LoadFrom("Sds.Osdr.Domain.BddTests.dll"),
                //Assembly.LoadFrom("Sds.Osdr.Domain.BackEnd.dll")
            };

            services.AddAllConsumers(allAssembly);

            services.AddScoped <Domain.BackEnd.EventHandlers.MachineLearningEventHandlers>();
            services.AddScoped <Domain.BackEnd.EventHandlers.MicroServiceEventHandlers>();

            var moduleAssemblies = new Assembly[]
            {
                Assembly.LoadFrom("Sds.Osdr.Generic.dll"),
                Assembly.LoadFrom("Sds.Osdr.RecordsFile.dll"),
                Assembly.LoadFrom("Sds.Osdr.Chemicals.dll"),
                Assembly.LoadFrom("Sds.Osdr.Crystals.dll"),
                Assembly.LoadFrom("Sds.Osdr.Reactions.dll"),
                Assembly.LoadFrom("Sds.Osdr.Spectra.dll"),
                Assembly.LoadFrom("Sds.Osdr.Pdf.dll"),
                Assembly.LoadFrom("Sds.Osdr.Images.dll"),
                Assembly.LoadFrom("Sds.Osdr.Office.dll"),
                Assembly.LoadFrom("Sds.Osdr.Tabular.dll"),
                Assembly.LoadFrom("Sds.Osdr.MachineLearning.dll"),
                Assembly.LoadFrom("Sds.Osdr.WebPage.dll"),
            };

            services.UseInMemoryOsdrModules(moduleAssemblies);

            services.AddSingleton((ctx) =>
            {
                return(_harness.Bus as IBusControl);
            });

            _harness.OnConfigureBus += cfg =>
            {
                cfg.UseInMemoryOutbox();

                cfg.RegisterScopedConsumer <Domain.BackEnd.EventHandlers.MachineLearningEventHandlers>(_serviceProvider, null, c => c.UseCqrsLite());
                cfg.RegisterScopedConsumer <Domain.BackEnd.EventHandlers.MicroServiceEventHandlers>(_serviceProvider, null, c => c.UseCqrsLite());

                cfg.RegisterInMemoryOsdrModules(_serviceProvider, moduleAssemblies);

                cfg.RegisterConsumers(_serviceProvider, allAssembly);

                cfg.UseRetry(r =>
                {
                    r.Interval(100, TimeSpan.FromMilliseconds(10));
                    r.Handle <MongoWriteException>();
                    r.Handle <UnhandledEventException>();
                    r.Handle <ConcurrencyException>();
                });
            };

            _harness.Handler <RecordsFile.Sagas.Events.RecordProcessed>(async context =>
            {
                lock (ProcessedRecords)
                {
                    var recordId = context.Message.Id;
                    var fileId   = context.Message.FileId;

                    if (!ProcessedRecords.ContainsKey(fileId))
                    {
                        ProcessedRecords[fileId] = new List <Guid>();
                    }

                    ProcessedRecords[fileId].Add(recordId);
                }

                await Task.CompletedTask;
            });

            _harness.Handler <Generic.Sagas.Events.FileProcessed>(async context =>
            {
                lock (ProcessedRecords)
                {
                    var recordId = context.Message.Id;
                    var parentId = context.Message.ParentId;

                    if (!DependentFiles.ContainsKey(parentId))
                    {
                        DependentFiles[parentId] = new List <Guid>();
                    }

                    DependentFiles[parentId].Add(recordId);
                }

                await Task.CompletedTask;
            });

            _harness.Handler <ModelTrainingFinished>(async context =>
            {
                lock (ProcessedRecords)
                {
                    var recordId = context.Message.Id;
                    var parentId = context.Message.ParentId;

                    if (!DependentFiles.ContainsKey(parentId))
                    {
                        DependentFiles[parentId] = new List <Guid>();
                    }

                    DependentFiles[parentId].Add(recordId);
                }

                await Task.CompletedTask;
            });

            _harness.Handler <RecordsFile.Sagas.Events.InvalidRecordProcessed>(async context =>
            {
                lock (InvalidRecords)
                {
                    var recordId = context.Message.Id;
                    var fileId   = context.Message.FileId;

                    if (!InvalidRecords.ContainsKey(fileId))
                    {
                        InvalidRecords[fileId] = new List <Guid>();
                    }

                    InvalidRecords[fileId].Add(recordId);
                }

                await Task.CompletedTask;
            });

            _harness.Handler <RecordsFile.Domain.Events.Records.StatusPersisted>(async context =>
            {
                if (context.Message.Status == RecordsFile.Domain.RecordStatus.Processed)
                {
                    lock (PersistedRecords)
                    {
                        if (!PersistedRecords.ContainsKey(context.Message.Id))
                        {
                            PersistedRecords[context.Message.Id] = 1;
                        }
                        else
                        {
                            PersistedRecords[context.Message.Id] = PersistedRecords[context.Message.Id] + 1;
                        }
                    }
                }

                await Task.CompletedTask;
            });

            _harness.Handler <Fault>(async context =>
            {
                Faults.AddRange(context.Message.Exceptions.Where(ex => !ex.ExceptionType.Equals("System.InvalidOperationException")));

                await Task.CompletedTask;
            });

            _serviceProvider = services.BuildServiceProvider();

            _harness.Start().Wait();

            Seed(JohnId, "John Doe", "John", "Doe", "john", "*****@*****.**", null).Wait();
            Seed(JaneId, "Jane Doe", "Jane", "Doe", "jane", "*****@*****.**", null).Wait();

            //  Specify how to compare DateTimes inside FluentAssertions
            AssertionOptions.AssertEquivalencyUsing(options =>
                                                    options
                                                    .Using <DateTime>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, (int)_harness.TestTimeout.TotalMilliseconds)).WhenTypeIs <DateTime>()
                                                    .Using <DateTimeOffset>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, (int)_harness.TestTimeout.TotalMilliseconds)).WhenTypeIs <DateTimeOffset>()
                                                    );
        }