예제 #1
0
        public async Task <IActionResult> Panel(PanelModel model)
        {
            if (!string.IsNullOrEmpty(model.code))
            {
                var pin = _dbContext.PinCodes.Where(o => o.Pin == model.code);
                if (pin.Any())
                {
                    model.code_invalid = false;

                    switch (model.action)
                    {
                    case "arm":
                        break;

                    case "disarm":
                        break;

                    case "arm_home":
                        break;

                    case "unlock":
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    model.code_invalid = true;
                }
            }
            return(Json(model));
        }
예제 #2
0
        public void ValidatePanelModel_Regex()
        {
            var panelModelNotValid = new PanelModel
            {
                Brand     = "Test",
                Latitude  = 90.0000000,
                Longitude = 179.0000001,
                Serial    = "AAAA1111BBBB2222"
            };

            var context1             = new ValidationContext(panelModelNotValid, null, null);
            var results1             = new List <ValidationResult>();
            var isModelStateNotValid = Validator.TryValidateObject(panelModelNotValid, context1, results1, true);

            var panelModelValid = new PanelModel
            {
                Brand     = "Test",
                Latitude  = -11.11,
                Longitude = 179.999999,
                Serial    = "AAAA1111BBBB2222"
            };

            var context2          = new ValidationContext(panelModelValid, null, null);
            var results2          = new List <ValidationResult>();
            var isModelStateValid = Validator.TryValidateObject(panelModelValid, context2, results2, true);


            // Assert
            Assert.False(isModelStateNotValid);
            Assert.True(isModelStateValid);
        }
예제 #3
0
        public async Task <IActionResult> Register([FromBody] PanelModel value)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var panel = new Panel
                {
                    Latitude  = value.Latitude,
                    Longitude = value.Longitude,
                    Serial    = value.Serial,
                    Brand     = value.Brand
                };

                await _panelRepository.InsertAsync(panel);

                return(Created($"panel/{panel.Id}", panel));
            }
            catch (System.Exception)
            {
                throw;
            }
        }
        public void PanelModelValidateData()
        {
            var panelModelNotValid = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 91,
                Longitude = 181,
                Serial    = "XXXX1111YYYY2222"
            };

            var context1             = new ValidationContext(panelModelNotValid, null, null);
            var results1             = new List <ValidationResult>();
            var isModelStateNotValid = Validator.TryValidateObject(panelModelNotValid, context1, results1, true);

            var panelModelValid = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 62.946264,
                Longitude = 180,
                Serial    = "XXXX1111YYYY2222"
            };

            var context           = new ValidationContext(panelModelValid, null, null);
            var results           = new List <ValidationResult>();
            var isModelStateValid = Validator.TryValidateObject(panelModelValid, context, results, true);


            // Assert
            Assert.False(isModelStateNotValid);
            Assert.True(isModelStateValid);
        }
        public async Task Register_ShouldInsertPanel()
        {
            var panel = new PanelModel
            {
                Brand     = "Ameren",
                Latitude  = 22.123456,
                Longitude = 88.123456,
                Serial    = "PYHJ564456677UII"
            };

            // Arrange
            panel.Latitude  = panel.Latitude + (panel.Latitude) * 0.6;
            panel.Longitude = panel.Longitude + (panel.Longitude) * 0.6;

            // Act
            var result = await _panelController.Register(panel);

            // Assert
            Assert.NotNull(result);

            var createdResult = result as CreatedResult;

            Assert.NotNull(createdResult);
            Assert.Equal(201, createdResult.StatusCode);
        }
예제 #6
0
        public async Task Get_ShouldGetObject()
        {
            // Arrange
            var panel = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };

            await _panelController.Register(panel);

            var panelId = "AAAA1111BBBB2222";
            // Act
            var result = await _analyticsController.Get(panelId);

            // Assert
            Assert.NotNull(result);

            var createdResult = result as OkResult;

            Assert.NotNull(createdResult);
            Assert.Equal(200, createdResult.StatusCode);
        }
예제 #7
0
        public async Task Register_ShouldInsertPanel()
        {
            var panel = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };

            // Arrange
            panel.Latitude  = panel.Latitude + (panel.Latitude) * 0.6;
            panel.Longitude = panel.Longitude + (panel.Longitude) * 0.6;

            // Act
            var result = await _panelController.Register(panel);

            // Assert
            Assert.NotNull(result);

            var createdResult = result as CreatedResult;

            Assert.NotNull(createdResult);
            Assert.Equal(201, createdResult.StatusCode);
        }
예제 #8
0
        public async Task PostTest()
        {
            var panel = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };
            await _genericRepositoryMock.Object.InsertAsync(panel);

            var data = new OneHourElectricityModel()
            {
                DateTime = DateTime.Now.Date.AddDays(-1), KiloWatt = 5
            };

            // Arrange
            // Act
            var result = await _analyticsController.Post("1", data);

            // Assert
            // Assert.NotNull(result);

            var createdResult = result as CreatedResult;

            Assert.NotNull(createdResult);
            Assert.Equal(201, createdResult.StatusCode);
        }
예제 #9
0
        public async Task Post_ShouldInsertAnalytics()
        {
            var panel = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };
            var oneHourElectricity = new OneHourElectricityModel
            {
                KiloWatt = 100,
                PanelId  = "1",
                DateTime = DateTime.UtcNow
            };
            // Act
            var result = await _analyticsController.Post("1", oneHourElectricity);

            // Assert
            Assert.NotNull(result);

            var createdResult = result as CreatedResult;

            Assert.NotNull(createdResult);
            Assert.Equal(201, createdResult.StatusCode);
        }
예제 #10
0
        public async Task GenericRepositoryGetAsync()
        {
            var panel = new PanelModel
            {
                Id        = 1,
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "XXXX1111YYYY2222"
            };
            Panel _panel = new Panel
            {
                Id        = 1,
                Brand     = "Brand1",
                Latitude  = 2.998877,
                Longitude = 33.887766,
                Serial    = "1234567890123456"
            };

            GenericRepositoryClass genericRepositoryClass = new GenericRepositoryClass();
            Panel panel1 = await genericRepositoryClass.GetAsync(_panel.Id.ToString());

            // Arrange

            // Act
            //var result = await _panelController.Register(panel1);

            //// Assert
            //Assert.NotNull(result);

            //var createdResult = result as CreatedResult;
            //Assert.NotNull(createdResult);
            //Assert.Equal(201, createdResult.StatusCode);
        }
예제 #11
0
        public async Task Register_ShouldInsertPanel()
        {
            var panel = new PanelModel
            {
                Id        = 1,
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };

            // Arrange

            // Act
            var result = await _panelController.Register(panel);

            // Assert
            Assert.NotNull(result);

            var createdResult = result as CreatedResult;

            Assert.NotNull(createdResult);
            Assert.Equal(201, createdResult.StatusCode);

            // Coverage DataAnnotation
            Assert.Throws <ValidationException>(() => Validator.ValidateObject(panel, new ValidationContext(panel, null, null), true));
        }
예제 #12
0
        public async Task Register_ShouldInsertPanel()
        {
            var panel = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };

            // Arrange

            // Act
            var result = await _panelController.Register(panel);

            // Assert
            Assert.NotNull(result);

            _panelRepositoryMock.Verify(x => x.InsertAsync(It.IsAny <Panel>()), Times.Once);

            var createdResult = result as CreatedResult;

            Assert.NotNull(createdResult);
            Assert.Equal(201, createdResult.StatusCode);
        }
예제 #13
0
        public async Task <IActionResult> Panel()
        {
            var model = new PanelModel();

            model.ArmState = await _alarmState.GetArmState();

            model.State = model.ArmState.ToString().ToLower();

            return(View(model));
        }
예제 #14
0
        public PopularPanelsModel GetPopularPanels()
        {
            var tournaments = this.tradingContentService.GetTournaments(new SearchTagsView());
            var panels      = new PopularPanelsModel();

            foreach (var tournament in tournaments)
            {
                var panel = new PanelModel
                {
                    Name = tournament.Name
                };

                var catSearch = new SearchTagsView();
                catSearch.Tags.Add(SearchBy.Tid, tournament.Id);
                var categories = this.tradingContentService.GetContextCategories(catSearch);

                foreach (var category in categories)
                {
                    // eg Semi Finals
                    var contextCat = new ContextCategoryDetails
                    {
                        Id   = category.Id,
                        Name = category.Name
                    };

                    var contextSearch = new SearchTagsView();
                    contextSearch.Tags.Add(SearchBy.CatId, category.Id);
                    var contexts = this.tradingContentService.GetContexts(contextSearch);

                    foreach (var context in contexts)
                    {
                        var contextView = new ContextModel
                        {
                            Id    = context.Id,
                            CatId = category.Id,
                            Label = context.Label
                        };

                        var selectionSearch = new SearchTagsView();
                        selectionSearch.Tags.Add(SearchBy.CId, context.Id);
                        var selections = this.tradingContentService.GetSelections(selectionSearch);
                        contextView.Selections = selections;


                        contextCat.Contexts.Add(contextView);
                    }

                    panel.ContextCategory.Add(contextCat);
                }

                panels.Panels.Add(panel);
            }

            return(panels);
        }
예제 #15
0
        public async void AnalyticsControllerTests_Day()
        {
            //insert pannel
            var panel = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };


            var result = await _panelController.Register(panel);

            // Assert
            Assert.NotNull(result);

            var createdResult = result as CreatedResult;

            Assert.NotNull(createdResult);
            Assert.Equal(201, createdResult.StatusCode);
            var createdpanel = createdResult.Value as Panel;
            int panelId      = createdpanel.Id;

            //inserting  records  to table

            await _anlyticsController.Post(panelId, new OneHourElectricityModel()
            {
                KiloWatt = 100,
                DateTime = date1_t1
            });


            await _anlyticsController.Post(panelId, new OneHourElectricityModel()
            {
                KiloWatt = 200,
                DateTime = date1_t2
            });


            var day1Result = _anlyticsController.DayResults(panelId, date1).Result;

            Assert.IsType <OkObjectResult>(day1Result);
            var day1records = day1Result as OkObjectResult;

            Assert.True(day1records.StatusCode == (int)HttpStatusCode.OK);
            Assert.IsAssignableFrom <IEnumerable <OneDayElectricityModel> >(day1records.Value);
            Assert.True((day1records.Value as IEnumerable <OneDayElectricityModel>).Count() == 1);
            var day1Record = (day1records.Value as IEnumerable <OneDayElectricityModel>).Single();

            Assert.Equal(150, day1Record.Average);
            Assert.Equal(100, day1Record.Minimum);
            Assert.Equal(200, day1Record.Maximum);
        }
예제 #16
0
        public void Register_PerformValidations()
        {
            //with  empty serial number

            var panel = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "1212121212121212"
            };


            var context = new ValidationContext(panel, null, null);
            var result  = new List <ValidationResult>();

            // Act
            var valid = Validator.TryValidateObject(panel, context, result, true);

            Assert.True(valid);

            //inavlid record (blank serial number

            panel = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = ""
            };

            context = new ValidationContext(panel, null, null);
            result  = new List <ValidationResult>();

            valid = Validator.TryValidateObject(panel, context, result, true);
            Assert.True(!valid);

            //invalid serial number

            panel = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "1123132`12`12`12`12"
            };

            context = new ValidationContext(panel, null, null);
            result  = new List <ValidationResult>();

            valid = Validator.TryValidateObject(panel, context, result, true);
            Assert.True(!valid);
        }
예제 #17
0
        public async Task Register_FailLongitude()
        {
            var panel = new PanelModel
            {
                Latitude  = -22.907104,
                Longitude = 190,
                Serial    = "wfQYyBSBKcRGUEKH",
                Brand     = "20"
            };

            var response = new HttpClient().PostAsJsonAsync(string.Concat(urlParameter, "api/panel/register"), panel).Result;

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
예제 #18
0
        public void SavePanelState(PanelModel model)
        {
            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            using var unitOfWork = _unitOfWorkFactory.Create();
            var repository = unitOfWork.GetRepository <PanelModel>();

            repository.Upsert(_panelKey, model);

            unitOfWork.SaveChanges();
        }
예제 #19
0
        public async Task Register_ShouldInsertPanel()
        {
            var panel = new PanelModel
            {
                Latitude  = -21.051542,
                Longitude = -47.051542,
                Serial    = "wfQYyBSBKcRGUEKH",
                Brand     = "Brand"
            };

            var response = new HttpClient().PostAsJsonAsync(string.Concat(urlParameter, "api/panel/register"), panel).Result;

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
예제 #20
0
        public async Task Register_LatitudeLongitudeCheck()
        {
            var panel = new PanelModel
            {
                Brand  = "Areva",
                Serial = "AAAA1111BBBB2222"
            };
            // Act
            var result = await _panelController.Register(panel);

            // Assert
            Assert.NotNull(result);
            var createdResult = result as CreatedResult;

            Assert.Null(createdResult);
        }
        public async Task ReturnsBadRequestWhenSerialNumberInvalid()
        {
            // Arrange
            var panel = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA11B222" //invalid serial no
            };

            // Act
            var result = await _panelController.Register(panel);

            // Assert
            Assert.NotNull(result);
            Assert.IsType <BadRequestObjectResult>(result);
        }
예제 #22
0
        public async Task Register_DecimalPlacesCheck()
        {
            var panel = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 12.345678123123,
                Longitude = 98.7655431232,
                Serial    = "AAAA1111BBBB2222"
            };
            // Act
            var result = await _panelController.Register(panel);

            // Assert
            Assert.NotNull(result);
            var createdResult = result as CreatedResult;

            Assert.Null(createdResult);
        }
예제 #23
0
        public async Task Register_ReturnsBadRequestResult_WhenLogitudeIsInvalid()
        {
            var panel = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 12.345345,
                Longitude = 98.7651,
                Serial    = "1234567890123456"
            };

            _panelController.ModelState.AddModelError("Longitude", "Invalid");
            var result = await _panelController.Register(panel);

            Assert.NotNull(result);
            var badRequestResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.IsType <SerializableError>(badRequestResult.Value);
        }
예제 #24
0
        public async Task <IActionResult> Register([FromBody] PanelModel item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var panel = new Panel
            {
                Latitude  = item.Latitude,
                Longitude = item.Longitude,
                Serial    = item.Serial,
                Brand     = item.Brand
            };

            await _panelRepository.InsertAsync(panel);

            return(Created($"panel/{panel.Id}", panel));
        }
예제 #25
0
        public async Task DayResults_ShouldGetDayResults()
        {
            // Arrange
            var panel = new PanelModel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB2222"
            };

            await _panelController.Register(panel);

            var panelId = "AAAA1111BBBB2222";
            OneHourElectricityModel value = new OneHourElectricityModel
            {
                KiloWatt = 10,
                DateTime = new System.DateTime()
            };
            var temp = new OneDayElectricityModel()
            {
                Sum      = 1,
                Average  = 1,
                Maximum  = 1,
                Minimum  = 1,
                DateTime = new System.DateTime()
            };
            await _analyticsController.Post(panelId, value);


            // Act
            var result = await _analyticsController.DayResults(panelId);



            // Assert
            Assert.NotNull(result);

            var createdResult = result as OkObjectResult;

            Assert.NotNull(createdResult);
            Assert.Equal(200, createdResult.StatusCode);
        }
        public IActionResult Panel()
        {
            var currentUserReservation = _reservationService.Get().OrderByDescending(x => x.ArriveDate)
                                         .FirstOrDefault(x => x.UserId == User.FindFirstValue(ClaimTypes.UserData));

            var model = new PanelModel
            {
                Reservations = _reservationService.Get().Count(x => x.DepartureDate.ToLocalTime() > DateTime.UtcNow),
            };

            if (_complaintsService.Get().Any())
            {
                model.Complaints = new List <ComplaintsModel>();
                foreach (var complaint in _complaintsService.Get())
                {
                    model.Complaints.Add(new ComplaintsModel
                    {
                        DateOfCreation = complaint.DateOfCreation.ToLocalTime(),
                        Department     = Enum.Parse <Departments>(complaint.Department),
                        Priority       = Enum.Parse <Priority>(complaint.Priority),
                        Description    = complaint.Description,
                        Title          = complaint.Title,
                        EmailAddress   = complaint.EmailAddress,
                        State          = complaint.State,
                        UserId         = complaint.UserId,
                        Id             = complaint.Id
                    });
                }
            }

            if (currentUserReservation != null)
            {
                model.CurrentUserReservationModel = new ReservationModel
                {
                    ArriveDate    = currentUserReservation.ArriveDate,
                    DepartureDate = currentUserReservation.DepartureDate,
                    EmailAddress  = currentUserReservation.EmailAddress,
                    PhoneNumber   = currentUserReservation.PhoneNumber
                };
            }

            return(View(model));
        }
예제 #27
0
        public void TestSettingsPersistence()
        {
            var collection     = new List <TabModel>();
            var repositoryMock = new Mock <IRepository <PanelModel> >();

            repositoryMock
            .Setup(m => m.GetById(PanelKey))
            .Returns(new PanelModel {
                Tabs = collection
            });
            repositoryMock
            .Setup(m => m.Upsert(PanelKey, It.IsAny <PanelModel>()))
            .Callback <string, PanelModel>((key, panelState) =>
            {
                collection.Clear();
                collection.AddRange(panelState.Tabs);
            });

            var unitOfWorkFactory = GetUnitOfWorkFactory(repositoryMock);

            IFilesPanelStateService filesPanelStateService = new FilesPanelStateService(
                unitOfWorkFactory, PanelKey);

            var tabs = Enumerable
                       .Range(0, 10)
                       .Select(_ => new TabModel())
                       .ToList();
            var state = new PanelModel {
                Tabs = tabs
            };

            filesPanelStateService.SavePanelState(state);

            var savedState = filesPanelStateService.GetPanelState();

            Assert.NotNull(savedState);
            Assert.NotNull(savedState.Tabs);
            Assert.True(savedState.Tabs.Count == tabs.Count);
            Assert.Equal(tabs, savedState.Tabs);
        }
예제 #28
0
        public async Task <IActionResult> Index()
        {
            var identityUser = await _userManager.GetUserAsync(HttpContext.User);

            Uyedetay kullanici = _uyedetayService.GetById(identityUser.uyeDetayId);
            Uye      uye       = _uyeService.GetById(identityUser.uyeId);
            string   rolName   = _rolService.GetById(kullanici.rol_id).rol_adi;

            List <Calisma>   calismalar = _calismaService.GetListByUyeId(identityUser.uyeDetayId);
            CalismaBilgileri studyInfo  = studyInfos(calismalar);

            List <Sinav> sinavlar = _sinavService.GetListByStatus(1);

            _model = new PanelModel
            {
                userDetail = new Entities.Dtos.UserDetail
                {
                    uyedetay_id    = identityUser.uyeDetayId,
                    uye_id         = identityUser.uyeId,
                    kullanici_adi  = identityUser.kullaniciAdi,
                    kullanici_mail = identityUser.kullaniciMail,
                    tema_id        = 1,
                    kayit_tarihi   = kullanici.kayit_tarihi,
                    uye_ad         = uye.uye_ad,
                    uye_soyad      = uye.uye_soyad,
                },
                rolAdi = rolName,
                toplamCalisilanZaman       = studyInfo.toplamCalisilanZaman,
                sonCalisilanSinav          = studyInfo.sonCalisilanSinav,
                sonCalismaTarihi           = studyInfo.sonCalismaTarihi,
                sinavaCalisilanToplamZaman = studyInfo.sinavaCalisilanZaman,
                sinavTarihi               = studyInfo.sinavTarihi,
                sonCalisilanDers          = studyInfo.sonCalisilanDers,
                derseCalisilanToplamZaman = studyInfo.derseCalisilanZaman,
                derseSonCalisilanZaman    = studyInfo.derseSonCalisilanZaman,
                aktifSinavlar             = sinavlar
            };
            return(View(_model));
        }
        public async Task <IActionResult> Register([FromBody] PanelModel value)
        {
            try
            {
                Regex regexObj = new Regex(@"-?\d{1,2}\.\d{6}");

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (!regexObj.Match(value.Latitude.ToString(CultureInfo.InvariantCulture)).Success)
                {
                    return(BadRequest(ModelState));
                }

                if (!regexObj.Match(value.Longitude.ToString(CultureInfo.InvariantCulture)).Success)
                {
                    return(BadRequest(ModelState));
                }

                var panel = new Panel
                {
                    Latitude  = Convert.ToDouble(value.Latitude),
                    Longitude = Convert.ToDouble(value.Longitude),
                    Serial    = value.Serial,
                    Brand     = value.Brand
                };

                await _panelRepository.InsertAsync(panel);

                return(Created($"panel/{panel.Id}", panel));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #30
0
    //fucntion for instatiating panels
    public void ShowPanel(string panelId)
    {
        PanelModel panelModel = Panels.FirstOrDefault(panel => panel.PanelID == panelId);

        if (panelModel != null)
        {
            //create a new panel instance
            var newPanelInstance = Instantiate(panelModel.PanelPrefab, transform);

            newPanelInstance.transform.localPosition = Vector3.zero;
            //Add this item to the queue
            _queue.Enqueue(new PanelInstanceModel
            {
                PanelId       = panelId,
                PanelInstance = newPanelInstance
            });
            Debug.Log("Panel Instantiated");
        }
        else
        {
            Debug.LogWarning($"Trying to use pane ID = {panelId}, but is not found in Panels list");
        }
    }