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); }
public async Task <IActionResult> Post([FromRoute, StringLength(16), Required] string panelId, [FromBody] OneHourElectricityModel value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // BUG FIX - Check Exists Panel if (!_panelRepository.Query().Any(x => x.Serial.Equals(panelId, StringComparison.CurrentCultureIgnoreCase))) { return(BadRequest()); } var oneHourElectricityContent = new OneHourElectricity { PanelId = panelId, KiloWatt = value.KiloWatt, DateTime = DateTime.UtcNow }; await _analyticsRepository.InsertAsync(oneHourElectricityContent); var result = new OneHourElectricityModel { Id = oneHourElectricityContent.Id, KiloWatt = oneHourElectricityContent.KiloWatt, DateTime = oneHourElectricityContent.DateTime }; return(Created($"panel/{panelId}/analytics/{result.Id}", result)); }
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); }
public async Task Post_ShouldInsertPanel() { var oneHour = new OneHourElectricityModel { KiloWatt = 1, }; // Arrange // Act var result = await _analyticsController.Post("panelID", oneHour); // Assert Assert.NotNull(result); _analyticsRepositoryMock.Verify(x => x.InsertAsync(It.IsAny <OneHourElectricity>()), Times.Once()); var createdResult = result as CreatedResult; Assert.NotNull(createdResult); Assert.Equal(201, createdResult.StatusCode); _analyticsRepositoryMock.ResetCalls(); }
public async Task Register_ShouldInsertAnalytics() { var oneHourElectricityContent = new OneHourElectricityModel { Id = 1, DateTime = new DateTime(2018, 1, 1), KiloWatt = 1500 }; var _panelRepositoryMock = new Mock <IPanelRepository>(); var _analiticsRepositoryMock = new Mock <IAnalyticsRepository>(); var _analiticsController = new AnalyticsController(_analiticsRepositoryMock.Object, _panelRepositoryMock.Object); // Arrange // Act var result = await _analiticsController.Post("AAAA1111BBBB2222", oneHourElectricityContent); // Assert Assert.NotNull(result); var createdResult = result as CreatedResult; Assert.NotNull(createdResult); Assert.Equal(201, createdResult.StatusCode); }
public async Task AnalyticsPost() { Panel _panel = new Panel { Id = 3, Brand = "Brand1", Latitude = 2.998877, Longitude = 33.887766, Serial = "1234567890123456" }; var oneHourElectricityModel = new OneHourElectricityModel() { Id = 4, KiloWatt = 9223372036854775807, DateTime = DateTime.Now }; // Arrange // Act IActionResult result = await _analyticsController.Post(_panel.Id.ToString(), oneHourElectricityModel); // Assert Assert.NotNull(result); var createdResult = result as CreatedResult; Assert.NotNull(createdResult); Assert.Equal(201, createdResult.StatusCode); }
public async Task <IActionResult> Post([FromBody] OneHourElectricityInsert value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var oneHourElectricityContent = new OneHourElectricity { KiloWatt = value.KiloWatt, DateTime = DateTime.UtcNow, PanelId = value.PanelId }; await _analyticsRepository.InsertAsync(oneHourElectricityContent); var result = new OneHourElectricityModel { Id = oneHourElectricityContent.Id, KiloWatt = oneHourElectricityContent.KiloWatt, DateTime = oneHourElectricityContent.DateTime, PanelId = oneHourElectricityContent.PanelId }; return(Created($"panel/{result.PanelId}/analytics/{result.Id}", result)); }
public async Task <IActionResult> Post([FromRoute] string panelId, [FromBody] OneHourElectricityModel value) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var oneHourElectricityContent = new OneHourElectricity { PanelId = panelId, KiloWatt = value.KiloWatt, DateTime = DateTime.UtcNow }; await _analyticsRepository.InsertAsync(oneHourElectricityContent); var result = new OneHourElectricityModel { Id = oneHourElectricityContent.Id, KiloWatt = oneHourElectricityContent.KiloWatt, DateTime = oneHourElectricityContent.DateTime }; return(Created($"panel/{panelId}/analytics/{result.Id}", result)); } catch (Exception) { throw; } }
public async Task <IActionResult> Post([FromRoute] int panelId, [FromBody] OneHourElectricityModel value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (_panelRepository.Query().Where(p => p.Id == panelId).SingleOrDefault() == null) { return(new UnauthorizedResult()); } var oneHourElectricityContent = new OneHourElectricity { PanelId = panelId, KiloWatt = value.KiloWatt, DateTime = value.DateTime }; await _analyticsRepository.InsertAsync(oneHourElectricityContent); var result = new OneHourElectricityModel { Id = oneHourElectricityContent.Id, KiloWatt = oneHourElectricityContent.KiloWatt, DateTime = oneHourElectricityContent.DateTime }; return(Created($"panel/{panelId}/analytics/{result.Id}", result)); }
public async Task <IActionResult> Post([FromRoute] int panelId, [FromBody] OneHourElectricityModel value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_panelRepository.Exist(panelId)) { return(NotFound()); } var oneHourElectricityContent = new OneHourElectricity { PanelId = panelId, KiloWatt = value.KiloWatt, DateTime = value.DateTime }; await _analyticsRepository.InsertAsync(oneHourElectricityContent); var result = new OneHourElectricityModel { Id = oneHourElectricityContent.Id, KiloWatt = oneHourElectricityContent.KiloWatt, DateTime = oneHourElectricityContent.DateTime }; return(Created($"panel/{panelId}/analytics/{result.Id}", result)); }
public async Task <IActionResult> Post([FromRoute] string panelId, [FromBody] OneHourElectricityModel value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var panel = await _panelRepository.Query() .FirstOrDefaultAsync(x => x.Serial.Equals(panelId, StringComparison.CurrentCultureIgnoreCase)); if (panel == null) { return(NotFound()); } var oneHourElectricityContent = new OneHourElectricity { PanelId = panelId, KiloWatt = value.KiloWatt, DateTime = DateTime.UtcNow }; await _analyticsRepository.InsertAsync(oneHourElectricityContent); var result = new OneHourElectricityModel { Id = oneHourElectricityContent.Id, KiloWatt = oneHourElectricityContent.KiloWatt, DateTime = oneHourElectricityContent.DateTime }; return(Created($"panel/{panelId}/analytics/{result.Id}", result)); }
public void OneHourElectricityListModelTest() { OneHourElectricityListModel listModel = new OneHourElectricityListModel(); OneHourElectricityModel oneHourElectricityModel = new OneHourElectricityModel() { Id = 1, KiloWatt = 23, DateTime = DateTime.Today }; listModel.OneHourElectricitys = new List <OneHourElectricityModel>() { oneHourElectricityModel }; var result = listModel.OneHourElectricitys; IEnumerable <OneHourElectricityModel> expected = new List <OneHourElectricityModel>() { (new OneHourElectricityModel() { Id = 1, KiloWatt = 23, DateTime = DateTime.Today }) }; Assert.All(expected, x => { foreach (var hourElectricityModel in result) { Assert.Equal(1, hourElectricityModel.Id); Assert.Equal(23, hourElectricityModel.KiloWatt); Assert.Equal(DateTime.Today, hourElectricityModel.DateTime); } }); Assert.Collection <OneHourElectricityModel>(result, elem1 => Assert.Equal(1, elem1.Id)); }
public async Task PostPanelData() { try { var panelData = new OneHourElectricityModel { Id = 123, KiloWatt = 5000, DateTime = DateTime.Now }; // Arrange // Act var result = await _AnalyticsController.Post(PanelID, panelData); // Assert Assert.NotNull(result); var createdResult = result as CreatedResult; Assert.NotNull(createdResult); Assert.Equal(201, createdResult.StatusCode); } catch (Exception) { throw; } }
public void TestModels() { OneHourElectricityModel oneHourElectricityModel = new OneHourElectricityModel(); oneHourElectricityModel.DateTime = DateTime.Now; oneHourElectricityModel.Id = 1; oneHourElectricityModel.KiloWatt = 234; OneHourElectricityListModel oneHourElectricityListModel = new OneHourElectricityListModel(); oneHourElectricityListModel.OneHourElectricitys.Add(oneHourElectricityModel); Assert.NotNull(oneHourElectricityListModel.OneHourElectricitys); Assert.NotNull(oneHourElectricityModel); OneDayElectricityModel oneDayElectricityModel = new OneDayElectricityModel(); oneDayElectricityModel.Average = 23; oneDayElectricityModel.DateTime = DateTime.UtcNow; oneDayElectricityModel.Maximum = 344; oneDayElectricityModel.Minimum = 24255; oneDayElectricityModel.Sum = 234446; Assert.NotNull(oneDayElectricityModel); }
public async Task Create_PostAnalystics() { string panelId = "1234567890987654"; var mockPanels = new List <Panel>() { new Panel { Brand = "Areva", Latitude = 12.345678, Longitude = 98.765543, Serial = panelId } }.AsQueryable().BuildMock(); _panelRepositoryMock.Setup(m => m.Query()).Returns(mockPanels.Object); var oneHourElectricityModel = new OneHourElectricityModel { Id = 1, DateTime = DateTime.Now, KiloWatt = 100 }; // Act var result = await _analyticsController.Post(panelId, oneHourElectricityModel); // Assert Assert.NotNull(result); var createdResult = result as CreatedResult; Assert.NotNull(createdResult); Assert.Equal(201, createdResult.StatusCode); }
public async Task <IActionResult> Post(string panelId, OneHourElectricityModel value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var oneHourElectricityContent = new OneHourElectricity { PanelId = panelId, KiloWatt = value.KiloWatt, DateTime = DateTime.UtcNow }; await _analyticsRepository.InsertAsync(oneHourElectricityContent); //var result = new OneHourElectricityModel //{ // Id = oneHourElectricityContent.Id, // KiloWatt = oneHourElectricityContent.KiloWatt, // DateTime = oneHourElectricityContent.DateTime //}; return(Created($"panel/{panelId}/analytics/{oneHourElectricityContent.Id}", oneHourElectricityContent)); }
public async Task Post_ShouldSaveSave() { //Setup Analytics Repository var createmodel = new OneHourElectricityModel() { Id = 1, KiloWatt = 2000, DateTime = DateTime.Now }; _analyticsRepositoryMock.Setup(repo => repo.InsertAsync(It.IsAny <OneHourElectricity>())) .Returns((OneHourElectricity t) => { t.Id = createmodel.Id; t.DateTime = createmodel.DateTime; t.KiloWatt = createmodel.KiloWatt; t.PanelId = panelId; return(Task.FromResult(1)); }); _anaController = new AnalyticsController(_analyticsRepositoryMock.Object, _panelRepositoryMock.Object); //Act var result = await _anaController.Post(panelId, createmodel); //Asserts var createResult = Assert.IsType <CreatedResult>(result); Assert.Equal(201, createResult.StatusCode); var resultModel = Assert.IsType <OneHourElectricityModel>(createResult.Value); Assert.Equal(createmodel.Id, resultModel.Id); Assert.Equal(createmodel.KiloWatt, resultModel.KiloWatt); Assert.Equal(createmodel.DateTime, resultModel.DateTime); }
public async Task RegisterAnalytics() { var panel = new OneHourElectricityModel { DateTime = DateTime.Now, KiloWatt = 35 }; var response = new HttpClient().PostAsJsonAsync(string.Concat(urlParameter, "panel/1/analytics"), panel).Result; Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
public void OneHourElectricityModelTest() { OneHourElectricityModel oneHour = new OneHourElectricityModel { Id = 1, KiloWatt = 23, DateTime = DateTime.Today }; Assert.Equal(1, oneHour.Id); Assert.Equal(23, oneHour.KiloWatt); Assert.Equal(DateTime.Today, oneHour.DateTime); }
public async Task _PostTestPanelIdNullOrEmpty() { // Arrange string panelId = ""; var data = new OneHourElectricityModel() { Id = 1, KiloWatt = 14000 }; // Act var result = await _analyticsController.Post(panelId, data); // Assert Assert.Equal(Assert.IsType <ContentResult>(result).Content, ("-1")); }
public async Task Post_CallInsert() { // Arrange OneHourElectricityModel oneHourElectricityModel = new OneHourElectricityModel() { DateTime = DateTime.Now, KiloWatt = 100 }; // Act var result = await _analyticsController.Post("AAAA1111BBBB2222", oneHourElectricityModel); // Assert _analyticsRepository.Verify(x => x.InsertAsync(It.IsAny <OneHourElectricity>()), Times.AtLeastOnce()); }
public async Task Post_ShouldReturnBadRequest() { // Arrange var electricityModel = new OneHourElectricityModel(); _analyticsController.ModelState.AddModelError("testField", "test Message"); // force validation error // Act var result = await _analyticsController.Post("AAAA1111BBBB2222", electricityModel); // Assert var createdResult = result as BadRequestObjectResult; Assert.Equal(400, createdResult.StatusCode); }
public async Task Post() { int panelId = 1; var model = new OneHourElectricityModel { DateTime = DateTime.UtcNow, KiloWatt = 1000 }; var result = await _analyticsController.Post(panelId, model); Assert.NotNull(result); var createdResult = result as CreatedResult; Assert.NotNull(createdResult); Assert.Equal(201, createdResult.StatusCode); }
public async Task Post_ShouldInsertOneHourElectricityContent() { // Arrange var electricityModel = new OneHourElectricityModel(); electricityModel.Id = 123; electricityModel.KiloWatt = 12345678; electricityModel.DateTime = DateTime.Now; // Act var result = await _analyticsController.Post("AAAA1111BBBB2222", electricityModel); // Assert var createdResult = result as CreatedResult; Assert.Equal(201, createdResult.StatusCode); Assert.Equal("panel/AAAA1111BBBB2222/analytics/0", createdResult.Location); }
public async Task Register_ShouldInsertOneHourElectricity() { var oneHourElectricityContent = new OneHourElectricityModel { KiloWatt = 1500, }; // Act var result = await _analyticsController.Post("AAAA1111BBBB2222", oneHourElectricityContent); // Assert Assert.NotNull(result); var createdResult = result as CreatedResult; Assert.NotNull(createdResult); Assert.Equal(201, createdResult.StatusCode); }
public void PostTest() { var model = new OneHourElectricityModel() { DateTime = DateTime.Now, KiloWatt = 100 }; var result = _controller.Post(1, model).Result; // Assert Assert.NotNull(result); var createdResult = result as CreatedResult; Assert.NotNull(createdResult); Assert.Equal(201, createdResult.StatusCode); }
public async Task Post_ReturnsCreatedResultOnPosting() { var panelId = "CCCC3333DDDD4444"; var oneHourElectricityContent = new OneHourElectricityModel { KiloWatt = 10, DateTime = DateTime.UtcNow }; // Act var result = await _analyticsController.Post(panelId, oneHourElectricityContent); // Assert Assert.NotNull(result); var createdResult = result as CreatedResult; Assert.NotNull(createdResult); Assert.Equal(201, createdResult.StatusCode); }
public async Task Post_ReturnsBadRequestResult_WhenModelIsInvalid() { var panelId = "CCCC3333DDDD4444"; var oneHourElectricityContent = new OneHourElectricityModel { DateTime = DateTime.UtcNow }; // Act _analyticsController.ModelState.AddModelError("KilloWatt", "Is Required"); var result = await _analyticsController.Post(panelId, oneHourElectricityContent); // Assert Assert.NotNull(result); var badRequestResult = Assert.IsType <BadRequestObjectResult>(result); Assert.IsType <SerializableError>(badRequestResult.Value); }
public async Task PostAnalytics_Success() { int panelID = 2; var analytics = new OneHourElectricityModel { Id = 15, KiloWatt = 124, DateTime = Convert.ToDateTime("2018-06-10 00:51:14.9630") }; var result = await _analyticsController.Post(panelID, analytics); Assert.NotNull(result); var createdResult = result as CreatedResult; Assert.NotNull(createdResult); Assert.Equal(201, createdResult.StatusCode); }
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); }