Exemple #1
0
        public void ModelIsNull()
        {
            // Arrange
            var validator = new AreaValidator(null, "", codeService);

            // Act
            validator.Validate(controller.ModelState);

            // Assert
            controller.ModelState.IsValid.Should().BeTrue();
        }
Exemple #2
0
        public void AreaWithDescriptionAndCeilingNullAndAltitudeNullIsValid()
        {
            var info = new Info();
            var area = new Area();
            area.Description = "U.S. nationwide and interests worldwide";
            area.Ceiling = null;
            area.Altitude = null;
            info.Areas.Add(area);

            var areaValidator = new AreaValidator(info);
            Assert.True(areaValidator.IsValid);
        }
Exemple #3
0
        public void ModelSetAndAreaDoesNotExist()
        {
            // Arrange
            codeServiceMockSetup.Setup(c => c.GetAreaByCodeAndType(It.IsAny <string>(), It.IsAny <string>())).Returns((VmOpenApiArea)null);
            var validator = new AreaValidator("areaCode", "", codeService);

            // Act
            validator.Validate(controller.ModelState);

            // Assert
            controller.ModelState.IsValid.Should().BeFalse();
        }
Exemple #4
0
        public void AreaWith4CoordinatePairsAndFirstAndLastPairEqualIsValid()
        {
            var info = new Info();
            var area = new Area();
            area.Description = "U.S. nationwide and interests worldwide";
            var polygon = new Polygon("68.47,-120.14 38.34,-119.95 38.52,-119.74 38.62,-119.89 38.47,-120.14");
            area.Polygons.Add(polygon);
            info.Areas.Add(area);

            var areaValidator = new AreaValidator(info);
            Assert.False(areaValidator.IsValid);
            var polygonsErrors = from error in areaValidator.Errors
                                 where error.GetType() == typeof(PolygonWithFirstCoordinatePairEqualToLastCoordinatePairError)
                                 select error;
            Assert.NotEmpty(polygonsErrors);
        }
Exemple #5
0
        public void AreaWithDescriptionAndCeilingAndAltitudeNullIsInvalid()
        {
            var info = new Info();
            var area = new Area();
            area.Description = "U.S. nationwide and interests worldwide";
            area.Ceiling = 123;
            area.Altitude = null;
            info.Areas.Add(area);

            var areaValidator = new AreaValidator(info);
            Assert.False(areaValidator.IsValid);

            var ceilingExistanceErrors = from error in areaValidator.Errors
                                         where error.GetType() == typeof(CeilingExistanceError)
                                         select error;
            Assert.NotEmpty(ceilingExistanceErrors);
        }
Exemple #6
0
        static async Task MainAsync(string[] arguments)
        {
            var versionString = Assembly.GetEntryAssembly()
                                .GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                                .InformationalVersion
                                .ToString();

            var recordCount = 10;
            var root        = "http://c4ponline.azurewebsites.net";
            var countryCode = arguments.Length == 1 || arguments.Length > 1 ? arguments[0] : string.Empty;
            var countCheck  = arguments.Length == 2 ? int.TryParse(arguments[1], out recordCount) : false;

            var url = $"{root}/Data/GetAvailableCallForPapers/{recordCount}/{countryCode}";

            if (string.IsNullOrEmpty(countryCode) || !AreaValidator.Validate(countryCode))
            {
                Console.Write(Environment.NewLine);
                Console.WriteLine($"C4P Online v{versionString}");
                Console.WriteLine("Usage: c4p <country> [count]");
                Console.WriteLine("Example: c4p [NA|SA|AF|EU|IT|AUS]");
                Console.Write(Environment.NewLine);
                return;
            }

            using (var client = new HttpClient())
            {
                var response = await client.GetAsync(url);

                if (response.IsSuccessStatusCode)
                {
                    var stringData = await response.Content.ReadAsStringAsync();

                    var typedResponse = JsonConvert.DeserializeObject <CallForPaperResponse>(stringData);
                    Console.Write(Environment.NewLine);

                    if (typedResponse.Proposals.Count() == 0)
                    {
                        Console.WriteLine($"There are no active Call for Papers at the moment in {countryCode}.");
                        Console.WriteLine($"Check back later or submit yours @ {root}");
                        Console.Write(Environment.NewLine);
                        return;
                    }

                    Console.WriteLine($"C4P Online v{versionString}");
                    Console.WriteLine($"Here are the available Call for Papers in {countryCode}");

                    foreach (var item in typedResponse.Proposals)
                    {
                        Console.WriteLine("--------------------------");
                        Console.WriteLine($"Conference Name: {item.ConferenceName}");
                        Console.WriteLine($"URL: {item.Website}");
                        Console.WriteLine($"Ends: {item.EndDate.ToString("MM/dd/yyyy")}");
                    }

                    Console.Write(Environment.NewLine);
                }
                else
                {
                    Console.WriteLine($"Sorry, there was an error fetching the available Call for Papers in {countryCode}");
                }
            }
        }
Exemple #7
0
        public void AreaWithOneDescriptionEmptyIsInvalid()
        {
            var info = new Info();
            var firstArea = new Area();
            firstArea.Description = "U.S. nationwide and interests worldwide";
            var secondArea = new Area();
            secondArea.Description = "";
            info.Areas.Add(firstArea);
            info.Areas.Add(secondArea);

            var areaValidator = new AreaValidator(info);
            Assert.False(areaValidator.IsValid);

            var emptyDescriptionErrors = from error in areaValidator.Errors
                                         where error.GetType() == typeof(AreaDescriptionRequiredError)
                                         select error;
            Assert.NotEmpty(emptyDescriptionErrors);
        }
Exemple #8
0
        public void AreaWithDescriptionIsValid()
        {
            var info = new Info();
            var area = new Area();
            area.Description = "U.S. nationwide and interests worldwide";
            info.Areas.Add(area);

            var areaValidator = new AreaValidator(info);
            Assert.True(areaValidator.IsValid);
        }
        public async Task <AreaDTO> Put(Guid instanceID, Guid userID, Guid identityWorkID, AreaValidator validator, IMapper mapper,
                                        AreaDTO AreaDTO)
        {
            var mgr   = new MiddlewareManager <Area>(new BaseRecordManager <Area>(), validator);
            var found = (await mgr.FindByExpressionAsync(x => x.ID == AreaDTO.ID, identityWorkID)).FirstOrDefault();

            if (found != null)
            {
                found.Name = AreaDTO.Name;
                await mgr.UpdateAsync(new List <Area>() { found }, identityWorkID);
            }
            else
            {
                return(await Post(instanceID, userID, identityWorkID, validator, mapper, AreaDTO));
            }

            return(AreaDTO);
        }
        public async Task <AreaDTO> Post(Guid instanceID, Guid userID, Guid identityWorkID, AreaValidator validator, IMapper mapper,
                                         AreaDTO AreaDTO)
        {
            Area dep = new Area();

            mapper.Map(AreaDTO, dep);
            dep.InstanceID = instanceID;
            dep.CompanyID  = identityWorkID;

            var mgr = new MiddlewareManager <Area>(new BaseRecordManager <Area>(), validator);
            await mgr.CreateAsync(new List <Area>() { dep }, identityWorkID);

            return(AreaDTO);
        }
 public async Task Delete(Guid instanceID, Guid userID, Guid identityWorkID, AreaValidator validator, IMapper mapper, Guid AreaID)
 {
     var mgr = new MiddlewareManager <Area>(new BaseRecordManager <Area>(), validator);
     await mgr.DeleteAsync(new List <Guid>() { AreaID }, identityWorkID);
 }