public async Task <IActionResult> GetLevelConfigurationsByCreatedById(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "LevelConfiguration/GetLevelConfigurationsByCreatedById")] HttpRequest req, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function(GetLevelConfigurationsByCreatedById) processed a request.");

            try
            {
                var accessTokenResult = _tokenProvider.ValidateToken(req);
                if (accessTokenResult.Status != AccessTokenStatus.Valid)
                {
                    return(new UnauthorizedResult());
                }

                Guid userAccountId = new Guid(accessTokenResult.Principal.Claims.First(c => c.Type == "UserAccount").Value);

                // possibly can speed this up/less calls by using advanced Dapper features
                var levelConfigurationRepo = new LevelConfigurationRepository();
                var targetZoneRepo         = new TargetZoneRepository();
                var targetRepo             = new TargetRepository();

                var levelConfigurations = levelConfigurationRepo.GetLevelConfigurationsByCreatedById(userAccountId);
                foreach (var levelConfigurationViewModel in levelConfigurations)
                {
                    levelConfigurationViewModel.TargetZone = targetZoneRepo.GetTargetZoneByLevelConfigurationId(levelConfigurationViewModel.LevelConfigurationId);
                    levelConfigurationViewModel.Targets    = targetRepo.GetTargetsByLevelConfigurationId(levelConfigurationViewModel.LevelConfigurationId);
                }

                return(new OkObjectResult(levelConfigurations));
            }
            catch (Exception exception)
            {
                return(new BadRequestObjectResult(exception.Message));
            }
        }
Ejemplo n.º 2
0
        private int Execute(IPackage package, IPackageOperationResolver resolver)
        {
            var packagesToMirror = resolver.ResolveOperations(package)
                                   .Where(o => o.Action == PackageAction.Install)
                                   .Select(o => o.Package)
                                   .ToList();

            int countMirrored = 0;

            foreach (var p in packagesToMirror)
            {
                if (TargetRepository.Exists(package))
                {
                    Logger.Log(MessageLevel.Info, NuGetResources.Log_PackageAlreadyPresent, p.GetFullName(), TargetRepository.Source);
                }
                else
                {
                    ExecuteMirror(p);
                    countMirrored++;
                    Logger.Log(MessageLevel.Info, NuGetResources.Log_PackageMirroredSuccessfully, p.GetFullName(), TargetRepository.Source);
                }
            }

            return(countMirrored);
        }
Ejemplo n.º 3
0
 private void ExecuteMirror(IPackage package)
 {
     if (!NoOp)
     {
         TargetRepository.AddPackage(package);
     }
 }
Ejemplo n.º 4
0
        public void Should_handle_basic_CRUD_operations()
        {
            // arrange
            var target = new TestTarget
            {
                Id   = 0,
                Data = new TestTargetData
                {
                    TestString = "Test Target Data"
                }
            };
            var dataProvider = new MssqlDataProvider();
            var repository   = new TargetRepository(dataProvider);

            // act
            var result = repository.Update(target);

            // assert
            Assert.That(result, Is.GreaterThan(0));

            // now Get
            var persistedTarget = repository.Get <TestTarget>(target.TableName, result);

            Assert.That(persistedTarget.Id, Is.GreaterThan(0));
            Assert.That(persistedTarget.Data, Is.Not.Null);

            var targetData = (TestTargetData)persistedTarget.Data;

            Assert.That(targetData.TestString, Is.EqualTo("Test Target Data"));

            // remove the record
            repository.Delete(persistedTarget);
        }
Ejemplo n.º 5
0
        private bool Execute(IPackage package, IPackageOperationResolver resolver)
        {
            var packagesToMirror = resolver.ResolveOperations(package)
                                   .Where(o => o.Action == PackageAction.Install)
                                   .Select(o => o.Package)
                                   .ToList();

            bool mirrored = false;

            foreach (var p in packagesToMirror)
            {
                if (TargetRepository.Exists(package))
                {
                    Logger.Log(MessageLevel.Info, NuGetResources.Log_PackageAlreadyPresent, p.GetFullName(), TargetRepository.Source);
                }
                else
                {
                    ExecuteMirror(p);
                    mirrored = true;
                }
            }

            if (mirrored)
            {
                Logger.Log(MessageLevel.Info, NuGetResources.Log_PackageAlreadyPresent, package.GetFullName(), TargetRepository.Source);
            }
            return(mirrored);
        }
Ejemplo n.º 6
0
        public void Should_handle_basic_CRUD_operations()
        {
            // arrange
            var target = new TestTarget
            {
                Id = 0,
                Data = new TestTargetData
                {
                    TestString = "Test Target Data"
                }
            };
            var dataProvider = new MssqlDataProvider();
            var repository = new TargetRepository(dataProvider);

            // act
            var result = repository.Update(target);

            // assert
            Assert.That(result, Is.GreaterThan(0));

            // now Get
            var persistedTarget = repository.Get<TestTarget>(target.TableName, result);
            Assert.That(persistedTarget.Id, Is.GreaterThan(0));
            Assert.That(persistedTarget.Data, Is.Not.Null);

            var targetData = (TestTargetData) persistedTarget.Data;
            Assert.That(targetData.TestString, Is.EqualTo("Test Target Data"));

            // remove the record
            repository.Delete(persistedTarget);
        }
Ejemplo n.º 7
0
        public void GenerateTargetsIntoDb()
        {
            List <Target> Targets = new List <Target>();
            var           repo    = new TargetRepository();

            using (var fs = new StreamReader(File.OpenRead(@"Names.csv")))
            {
                fs.ReadLine();
                while (!fs.EndOfStream)
                {
                    string   Line   = fs.ReadLine();
                    string[] data   = Line.Split(',');
                    var      target = new Target
                    {
                        TargetId  = Guid.NewGuid(),
                        GivenName = data[18],
                        Surname   = data[0],
                        Gender    = (data[17] == "Male")? Gender.Male : Gender.Female,
                        Address   = new Address {
                            AddressLine1 = data[1], StateProvince = data[2], PostalCode = data[3]
                        },
                        Birthdate    = DateTime.ParseExact(data[9], "M/d/yyyy", CultureInfo.InvariantCulture),
                        EmailAddress = data[4],
                        Telephone    = new PhoneNumber {
                            Number = data[7]
                        }
                    };
                    repo.Add(target);
                }
            }
        }
Ejemplo n.º 8
0
        public Target CreateTarget(Wing wing, Guid guid, Type type, bool isTrendingEnabled, int displayOrder)
        {
            var result = TargetRepository.New(wing, guid, this.Name);

            result.Description       = this.Description;
            result.ClrType           = type.AssemblyQualifiedName;
            result.IsReferenceTarget = this.IsReferenceTarget;
            result.DisplayOrder      = displayOrder;
            result.IsDisabled        = false;
            result.Publisher         = this.PublisherName ?? "Unknown";
            result.PublisherEmail    = this.PublisherEmail ?? "";
            result.PublisherWebsite  = this.PublisherWebsite ?? "";
            result.IsTrendingEnabled = isTrendingEnabled;
            var assemblyVersion = type.Assembly.GetName().Version;

            result.Version = new Version
            {
                Major     = assemblyVersion.Major,
                Minor     = assemblyVersion.Minor,
                Milestone = assemblyVersion.Revision
                            //Number = string.Format("{0}.{1}.{2}", assemblyVersion.Major, assemblyVersion.Minor,
                            //                       assemblyVersion.Revision)
            };
            return(result);
        }
Ejemplo n.º 9
0
 private void ExecuteMirror(IPackage package)
 {
     if (!NoOp)
     {
         TargetRepository.AddPackage(package);
     }
     Logger.Log(MessageLevel.Info, NuGetResources.Log_PackageMirroredSuccessfully, package.GetFullName(), TargetRepository.Source);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Находит цель геолокации с указанным идентификатором
        /// </summary>
        /// <param name="targetId">Идентификатор цели геолокации</param>
        /// <returns></returns>
        private Target FindTarget(Guid targetId)
        {
            Target target = TargetRepository.FindById(targetId);

            if (target == null)
            {
                throw new ArgumentException("Не найдена цель геолокации с указанным идентификатором", "targetId");
            }

            return(target);
        }
Ejemplo n.º 11
0
        public void GetTargetById_TargetIdEqualsResultId()
        {
            //Arrange
            var repository = new TargetRepository(this._context);

            //Act
            var target = repository.GetTargetById(1);

            //Assert
            Assert.Equal(1, target.Id);
        }
Ejemplo n.º 12
0
        public void ReadAllTargetsNotEmpty()
        {
            //Arrange
            var repository = new TargetRepository(this._context);

            //Act
            var targets = repository.Read() as IEnumerable <Target>;

            //Assert
            Assert.NotEmpty(targets);
        }
Ejemplo n.º 13
0
        public ActionResult AddTarget(CreateTargetRequest createRequest)
        {
            var repository = new TargetRepository();

            var newTarget = repository.AddTarget(createRequest.Name,
                                                 createRequest.Location,
                                                 createRequest.FitnessLevel,
                                                 createRequest.UserId);

            return(Created($"/api/target/{newTarget.Id}", newTarget));
        }
        public void ApplyValueTestPositive()
        {
            var target    = new FooTarget();
            var targetDef = TargetRepository.New(DoubleFactory.DummyWing, Guid.Empty, "FooTarget");
            var element   = DoubleFactory.CreateElementDouble(targetDef, "SomeInt");

            var model = new ElementMappingModel <FooTarget>(element, Enumerable.Empty <CrosswalkViewModel>());

            model.ApplyValue(target, 100);
            Assert.AreEqual(target.SomeInt, 100);
        }
Ejemplo n.º 15
0
        public void TargetNameEqualHarchi()
        {
            //Arrange
            var repository = new TargetRepository(this._context);

            //Act
            var target = repository.GetTargetByName("Харчі") as Target;

            //Assert
            Assert.Equal("Харчі", target?.TargetName);
        }
Ejemplo n.º 16
0
        public void GetTargetByName_TargetNull()
        {
            //Arrange
            var repository = new TargetRepository(this._context);

            //Act
            var target = repository.GetTargetByName("Харчі") as Target;

            //Assert
            Assert.NotNull(target);
        }
Ejemplo n.º 17
0
        public void GetTargetById_TargetNotNull()
        {
            //Arrange
            var repository = new TargetRepository(this._context);

            //Act
            var target = repository.GetTargetById(1);

            //Assert
            Assert.NotNull(target);
        }
Ejemplo n.º 18
0
        public void TargetNameEqualHarchi()
        {
            //Arrange
            var          repository = new TargetRepository(this._context);
            const string targetName = "Харчі";

            //Act
            var target = repository.GetTargetByName(targetName) as Target;

            //Assert
            Assert.Equal(targetName, target.TargetName);
        }
Ejemplo n.º 19
0
 public TargetService(IpGeoBaseContext dataContext)
 {
     DataContext = dataContext;
     TargetRepository = new TargetRepository(dataContext);
     CountryRuleRepository = new CountryRuleRepository(dataContext);
     AreaRuleRepository = new AreaRuleRepository(dataContext);
     AreaRepository = new AreaRepository(dataContext);
     RegionRuleRepository = new RegionRuleRepository(dataContext);
     RegionRepository = new RegionRepository(dataContext);
     LocationRuleRepository = new LocationRuleRepository(dataContext);
     LocationRepository = new LocationRepository(dataContext);
 }
Ejemplo n.º 20
0
 public TargetService(IpGeoBaseContext dataContext)
 {
     DataContext            = dataContext;
     TargetRepository       = new TargetRepository(dataContext);
     CountryRuleRepository  = new CountryRuleRepository(dataContext);
     AreaRuleRepository     = new AreaRuleRepository(dataContext);
     AreaRepository         = new AreaRepository(dataContext);
     RegionRuleRepository   = new RegionRuleRepository(dataContext);
     RegionRepository       = new RegionRepository(dataContext);
     LocationRuleRepository = new LocationRuleRepository(dataContext);
     LocationRepository     = new LocationRepository(dataContext);
 }
        public void ApplyValueTestWrongType()
        {
            var target    = new FooTarget();
            var targetDef = TargetRepository.New(DoubleFactory.DummyWing, Guid.Empty, "FooTarget");
            var element   = DoubleFactory.CreateElementDouble(targetDef, "SomeInt");

            string expected = "zzzzzzzzzzzzzzz";
            var    model    = new ElementMappingModel <FooTarget>(element, Enumerable.Empty <CrosswalkViewModel>());

            // a string is assigned, so test that it's not equal to the SomeInt property
            model.ApplyValue(target, expected);
            Assert.AreNotEqual(expected, target.SomeInt);
        }
    // Use this for initialization
    void Start()
    {
        var target = new Target(transform);

        if (Navigation)
        {
            TargetRepository.RegisterNavigationTarget(target);
        }
        if (Shooting)
        {
            TargetRepository.RegisterTarget(target);
        }
    }
        public void ApplyValueStringToIntTest()
        {
            var target    = new FooTarget();
            var targetDef = TargetRepository.New(DoubleFactory.DummyWing, Guid.Empty, "FooTarget");
            var element   = DoubleFactory.CreateElementDouble(targetDef, "SomeInt");

            var    expected      = 123;
            string ValueToAssign = expected.ToString();
            var    model         = new ElementMappingModel <FooTarget>(element, Enumerable.Empty <CrosswalkViewModel>());

            model.ApplyValue(target, ValueToAssign);
            Assert.AreEqual(expected, target.SomeInt);
        }
Ejemplo n.º 24
0
        public void Delete_TargetNotExists()
        {
            //Arrange
            var repository = new TargetRepository(this._context);

            //Act
            var count = _context.Targets.Local.Count;

            repository.Delete(3);
            this._context.SaveChanges();

            //Assert
            Assert.Equal(count - 1, _context.Targets.Local.Count);
        }
        public void ApplyValueStringToDoubleIntoIntTest()
        {
            var target    = new FooTarget();
            var targetDef = TargetRepository.New(DoubleFactory.DummyWing, Guid.Empty, "FooTarget");
            var element   = DoubleFactory.CreateElementDouble(targetDef, "SomeInt");

            var    expected      = 123.45;
            string ValueToAssign = expected.ToString();

            var model = new ElementMappingModel <FooTarget>(element, Enumerable.Empty <CrosswalkViewModel>());

            // a string is assigned, so test that it's not equal to the SomeInt property
            model.ApplyValue(target, ValueToAssign);
            Assert.AreNotEqual((int)expected, target.SomeInt);
        }
        public void ApplyValueScopeTest()
        {
            // given an element with name "SomeEnum"
            var target    = new FooTarget();
            var targetDef = TargetRepository.New(DoubleFactory.DummyWing, Guid.Empty, "FooTarget");

            var element = DoubleFactory.CreateElementDouble(targetDef, "SomeEnum");

            // find that property on target

            var model = new ElementMappingModel <FooTarget>(element, Enumerable.Empty <CrosswalkViewModel>());

            // set target's SomeEnum property value to "Something.value3"
            model.ApplyValue(target, Something.value3);
            Assert.AreEqual(target.SomeEnum, Something.value3);
        }
        public void TestWarnings()
        {
            var wing        = WingRepository.New(Guid.NewGuid().ToString());
            var target      = TargetRepository.New(wing, Guid.Empty, Guid.NewGuid().ToString());
            var mapper      = new TargetMapper <FooTarget>(target, Enumerable.Empty <MappedFieldEntryViewModel>());
            var po          = new PrivateObject(mapper);
            var ElementMaps = po.GetProperty("ElementMaps") as IDictionary;

            Assert.IsTrue(ElementMaps.Count > 0);

            var errors = new List <ValidationError>();
            var engine = new InstanceValidator <FooTarget>();
            var result = engine.ValidateInstance(mapper.Target);

            Assert.IsTrue(result.PropertyWarnings.Count > 0);
        }
Ejemplo n.º 28
0
        public void Update_TargetFieldsAreEqualWithResultFields()
        {
            //Arrange
            var repository = new TargetRepository(this._context);

            //Act
            var item = new Entities.Target {
                Id = 1, TargetName = "Приладдя", OrganizationId = 3
            };
            var target = repository.Update(item);

            this._context.SaveChanges();

            //Assert
            Assert.Equal(1, target.Id);
            Assert.Equal(item.TargetName, target.TargetName);
            Assert.Equal(3, target.OrganizationId);
        }
Ejemplo n.º 29
0
        public void CreateNewTarget_FakeDbContext()
        {
            //Arrange
            var repository = new TargetRepository(this._context);

            //Act
            var item = new Entities.Target {
                Id = 5, TargetName = "Приладдя", OrganizationId = 3
            };
            var result = repository.Create(item);

            this._context.SaveChanges();

            //Assert
            Assert.IsType <Entities.Target>(result);
            Assert.Equal(item.TargetName, result.TargetName);
            Assert.True(this._context.Targets.Local.Count == 4);
        }
        public void GenericApplyValueStringToDoubleIntoIntTest()
        {
            var target    = new FooTarget();
            var targetDef = TargetRepository.New(DoubleFactory.DummyWing, Guid.Empty, "FooTarget");
            var element   = DoubleFactory.CreateElementDouble(targetDef, "SomeInt");

            var    expected      = 123.45;
            string ValueToAssign = expected.ToString();
            var    type          = typeof(ElementMappingModel <>);

            type = type.MakeGenericType(typeof(FooTarget));
            var ctor  = type.GetConstructor(new[] { typeof(Element), typeof(IEnumerable <CrosswalkViewModel>) });
            var model = ctor.Invoke(new object[] { element, Enumerable.Empty <CrosswalkViewModel>() });
            var pi    = type.GetMethod("ApplyValue");

            // a string is assigned, so test that it's not equal to the SomeInt property
            pi.Invoke(model, new object[] { target, ValueToAssign });
            Assert.AreNotEqual((int)expected, target.SomeInt);
        }
Ejemplo n.º 31
0
        public static void Initialize()
        {
            // verify tables
            var dataProvider = new MssqlDataProvider();
            var hierarchyDataProvider = new MssqlHierarchyDataProvider(dataProvider);

            var hierarchyEntryRepository = new HierarchyEntryRepository(dataProvider);
            var targetEntryRepository = new TargetEntryRepository(dataProvider);
            var targetRepository = new TargetRepository(dataProvider);

            var assembly = Assembly.GetCallingAssembly();
            var targetTypes = assembly.GetTypesOfType<ITarget>();

            var hierarchyService = new HierarchyService(hierarchyDataProvider, hierarchyEntryRepository, targetEntryRepository, targetRepository, targetTypes);

            // build missing tables

            // register structureMap
        }
Ejemplo n.º 32
0
        public static Target CreateTarget(
            this DynamicTarget target, Wing wing)
        {
            var result = TargetRepository.New(wing, target.Id, target.Name);

            if (result.Guid == Guid.Empty)
            {
                result.Guid = Guid.NewGuid();
            }

            result.Description          = target.Description;
            result.ClrType              = null;
            result.IsReferenceTarget    = false;
            result.DisplayOrder         = target.DisplayOrder;
            result.IsCustom             = true;
            result.DbSchemaName         = target.DbSchemaName;
            result.CreateSqlScript      = target.CreateTableScript;
            result.ImportSQLScript      = target.ImportSQLScript;
            result.AddMeausersSqlScript = target.AddMeasuresScript;
            result.AddReportsSqlScript  = target.AddReportsScript;
            result.AllowMultipleImports = target.AllowMultipleImports;
            result.ImportType           = target.ImportSteps.Type;

            result.Publisher        = target.Publisher;
            result.PublisherEmail   = target.PublisherEmail;
            result.PublisherWebsite = target.PublisherWebsite;
            result.Version          = new Version {
                Number = target.Version
            };
            result.IsDisabled            = target.IsDisabled;
            result.WingTargetXmlFilePath = target.WingTargetXmlFilePath;
            result.TemplateFileName      = target.TempateFileName;

            if (wing.Targets.All(t => t.Guid != result.Guid || !t.Name.EqualsIgnoreCase(result.Name)))
            {
                wing.Targets.Add(result);
            }

            return(result);
        }
Ejemplo n.º 33
0
        public void TargetRepository()
        {
            Mock <IDbSetFactory>   factory = new Mock <IDbSetFactory>();
            Mock <DbSet <Target> > dbSet   = new Mock <DbSet <Target> >();

            factory.Setup(m => m.CreateDbSet <Target>()).Returns(dbSet.Object);

            TargetRepository repo = new TargetRepository(factory.Object);

            var Target = new Target();

            var sequence = new MockSequence();

            dbSet.InSequence(sequence).Setup(e => e.Add(Target));
            dbSet.InSequence(sequence).Setup(e => e.Find(Target.Id));
            dbSet.InSequence(sequence).Setup(e => e.Find(Target.Id));
            dbSet.InSequence(sequence).Setup(e => e.Find(Target.Id));
            repo.Create(Target);
            repo.Get(Target.Id);
            repo.Update(Target);
            repo.Delete(Target.Id);
        }
Ejemplo n.º 34
0
 public Locator(IpGeoBaseContext dataContext)
 {
     DataContext = dataContext;
     RangeRepository = new RangeRepository(dataContext);
     TargetRepository = new TargetRepository(dataContext);
 }
        public void TargetRepository()
        {
            Mock<IDbSetFactory> factory = new Mock<IDbSetFactory>();
            Mock<DbSet<Target>> dbSet = new Mock<DbSet<Target>>();

            factory.Setup(m => m.CreateDbSet<Target>()).Returns(dbSet.Object);

            TargetRepository repo = new TargetRepository(factory.Object);

            var Target = new Target();

            var sequence = new MockSequence();
            dbSet.InSequence(sequence).Setup(e => e.Add(Target));
            dbSet.InSequence(sequence).Setup(e => e.Find(Target.Id));
            dbSet.InSequence(sequence).Setup(e => e.Find(Target.Id));
            dbSet.InSequence(sequence).Setup(e => e.Find(Target.Id));
            repo.Create(Target);
            repo.Get(Target.Id);
            repo.Update(Target);
            repo.Delete(Target.Id);
        }