Exemplo n.º 1
0
        public void CreateSholdCreateAddPanelToDictionaryAndSave()
        {
            //arrange
            DateTime   date  = DateTime.Parse("02/02/2019");
            SolarPanel panel = new SolarPanel
            {
                Section       = "TestSection",
                Row           = 8,
                Column        = 8,
                DateInstalled = date,
                Material      = MaterialType.AmorphousSilicon,
                IsTracking    = false
            };
            string testFileName           = $"Test{DateTime.Now.Ticks}.csv";
            FileSolarPanelRepository repo = new FileSolarPanelRepository(testFileName);

            //act
            repo.Create(panel);
            Dictionary <string, SolarPanel> panelList = repo.ReadAll();

            //assert
            Assert.IsNotNull(panelList);
            Assert.IsNotNull(panelList["TestSection-8-8"]);
            Assert.AreEqual(1, panelList.Count);
            Assert.AreEqual(DateTime.Parse("02/02/2019"), panelList["TestSection-8-8"].DateInstalled);
            Assert.AreEqual(MaterialType.AmorphousSilicon, panelList["TestSection-8-8"].Material);
            Assert.IsFalse(panelList["TestSection-8-8"].IsTracking);
            File.Delete(testFileName);
        }
Exemplo n.º 2
0
        public void DeleteShouldRemovePanelAndSaveFile()
        {
            //Arrange
            string testFile = "TestDataDeleteBefore.csv";
            ISolarPanelRepository beforeRepo = new FileSolarPanelRepository(testFile);

            string afterFile = "TestDataDeleteAfter.csv";
            ISolarPanelRepository afterRepo = new FileSolarPanelRepository(afterFile);

            SolarPanel panel = new SolarPanel
            {
                Section       = "DeleterTest",
                Row           = 2,
                Column        = 3,
                DateInstalled = DateTime.Parse("03/03/2020"),
                Material      = MaterialType.CadmiumTelluride,
                IsTracking    = true
            };

            beforeRepo.Create(panel);

            //Act
            Dictionary <string, SolarPanel> panelList = beforeRepo.ReadAll();

            beforeRepo.Delete(panel);

            //Assert
            Assert.IsFalse(panelList.ContainsKey("DeleterTest-2-3"));
            Assert.AreEqual(0, panelList.Count);
            Assert.AreEqual(afterRepo.ReadAll(), beforeRepo.ReadAll());

            File.Delete(testFile);
        }
Exemplo n.º 3
0
        public void ReadBySectionShouldReturnAllPanelsInSection()
        {
            //arrange
            FileSolarPanelRepository        repo    = new FileSolarPanelRepository("TestDataBLLRead.csv");
            SolarPanelService               service = new SolarPanelService(repo);
            Dictionary <string, SolarPanel> firstSection;
            Dictionary <string, SolarPanel> secondSection;
            ListOfPanelsResult              firstResult  = new ListOfPanelsResult();
            ListOfPanelsResult              secondResult = new ListOfPanelsResult();

            //act
            firstResult  = service.ReadBySection("Test1");
            secondResult = service.ReadBySection("Test2");

            firstSection  = firstResult.Data;
            secondSection = secondResult.Data;

            //assert
            Assert.IsNotNull(firstSection);
            Assert.IsNotNull(secondSection);
            Assert.AreEqual(3, firstSection.Count);
            Assert.AreEqual(2, secondSection.Count);
            Assert.IsTrue(firstSection["Test1-100-3"].IsTracking);
            Assert.IsFalse(secondSection["Test2-1-3"].IsTracking);
        }
Exemplo n.º 4
0
        public void DeletePanelShouldDeleteGivenPanelAndReturnResult()
        {
            //arrange
            string testFileName              = $"Test{DateTime.Now.Ticks}.csv";
            FileSolarPanelRepository repo    = new FileSolarPanelRepository(testFileName);
            SolarPanelService        service = new SolarPanelService(repo);
            SolarPanel toDeletePanel         = new SolarPanel
            {
                Section       = "TestSection",
                Row           = 8,
                Column        = 8,
                DateInstalled = DateTime.Parse("10/01/2021"),
                Material      = MaterialType.MulticrystallineSilicon,
                IsTracking    = true
            };

            //act
            service.Create(toDeletePanel);
            SolarPanelResult result = service.Delete(toDeletePanel);

            //assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual($"{toDeletePanel.GetKey()} removed.", result.Message);
            Assert.AreEqual(toDeletePanel, result.Data);
        }
Exemplo n.º 5
0
        public void CreateShouldHappenIfPanelIsValid()
        {
            //arrange
            DateTime   date  = DateTime.Parse("02/02/2019");
            SolarPanel panel = new SolarPanel
            {
                Section       = "TestSection",
                Row           = 8,
                Column        = 8,
                DateInstalled = date,
                Material      = MaterialType.AmorphousSilicon,
                IsTracking    = false
            };
            string testFileName              = $"Test{DateTime.Now.Ticks}.csv";
            FileSolarPanelRepository repo    = new FileSolarPanelRepository(testFileName);
            SolarPanelService        service = new SolarPanelService(repo);

            //act
            SolarPanelResult result = service.Create(panel);

            //assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual("Success. TestSection-8-8 added.", result.Message);
            Assert.AreEqual(panel, result.Data);
            File.Delete(testFileName);
        }
Exemplo n.º 6
0
        public void CreateShouldNotHappenIfPanelIsInvalid(string section, int row, int column, string date, string material, string isTracking)
        {
            //arrange
            SolarPanel panel = new SolarPanel
            {
                Section       = section,
                Row           = row,
                Column        = column,
                DateInstalled = DateTime.Parse(date),
                Material      = Enum.Parse <MaterialType>(material),
                IsTracking    = bool.Parse(isTracking)
            };
            ISolarPanelRepository repo    = new FileSolarPanelRepository("TestDataBLLBadCreate.csv");
            SolarPanelService     service = new SolarPanelService(repo);

            //act
            SolarPanelResult result = service.Create(panel);

            //assert
            Assert.IsFalse(result.Success);
            Assert.IsNotEmpty(result.Message);
            Assert.IsNotNull(result.Message);
            Assert.AreEqual(panel, result.Data);
            Assert.AreEqual(1, repo.ReadAll().Count);
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            ISolarPanelRepository repo    = new FileSolarPanelRepository("FullTestData.csv");
            SolarPanelService     service = new SolarPanelService(repo);
            SolarPanelController  solarPanelController = new SolarPanelController(service);

            solarPanelController.Run();
        }
Exemplo n.º 8
0
        public void ConstructorShouldLoadFileIntoDictionary()
        {
            //arrange
            string testFile            = "TestDataConstructor.csv";
            ISolarPanelRepository repo = new FileSolarPanelRepository(testFile);

            //act
            Dictionary <string, SolarPanel> panelList = repo.ReadAll();

            //Assert
            Assert.IsNotNull(panelList);
            Assert.IsNotNull(panelList["Main-1-1"]);
            Assert.AreEqual(1, panelList.Count);
            Assert.AreEqual(DateTime.Parse("01/01/2020"), panelList["Main-1-1"].DateInstalled);
            Assert.AreEqual(MaterialType.MulticrystallineSilicon, panelList["Main-1-1"].Material);
            Assert.IsTrue(panelList["Main-1-1"].IsTracking);
        }
Exemplo n.º 9
0
        public void ReadBySectionShouldReturnNullAndFalseIfNotPresent()
        {
            //arrange
            FileSolarPanelRepository        repo    = new FileSolarPanelRepository("TestDataBLLRead.csv");
            SolarPanelService               service = new SolarPanelService(repo);
            Dictionary <string, SolarPanel> notASection;
            ListOfPanelsResult              result = new ListOfPanelsResult();

            //act
            result      = service.ReadBySection("Test3");
            notASection = result.Data;

            //assert
            Assert.IsNull(notASection);
            Assert.IsFalse(result.Success);
            Assert.AreEqual("No panels found in that section", result.Message);
        }
Exemplo n.º 10
0
        public void ReadSinglePanelShouldReturnFalseAndNullIfNotPresent()
        {
            //arrange
            FileSolarPanelRepository repo    = new FileSolarPanelRepository("TestDataBLLRead.csv");
            SolarPanelService        service = new SolarPanelService(repo);
            SolarPanel       resultingPanel;
            SolarPanelResult result = new SolarPanelResult();


            //act
            result         = service.ReadSinglePanel("Test1", 51, 2);
            resultingPanel = result.Data;

            //assert
            Assert.IsNull(resultingPanel);
            Assert.IsFalse(result.Success);
            Assert.AreEqual(result.Message, "Panel not found");
        }
Exemplo n.º 11
0
        public void UpdatePanelShouldReturnNullAndFalseIfUpdatesInvalid()
        {
            //arrange
            DateTime   date  = DateTime.Parse("02/02/2019");
            SolarPanel panel = new SolarPanel
            {
                Section       = "TestSection",
                Row           = 8,
                Column        = 8,
                DateInstalled = date,
                Material      = MaterialType.AmorphousSilicon,
                IsTracking    = false
            };

            SolarPanel upatePanel = new SolarPanel
            {
                Section       = "TestSection",
                Row           = 8,
                Column        = 8,
                DateInstalled = DateTime.Parse("10/01/2021"),
                Material      = MaterialType.MulticrystallineSilicon,
                IsTracking    = true
            };
            string testFileName              = $"Test{DateTime.Now.Ticks}.csv";
            FileSolarPanelRepository repo    = new FileSolarPanelRepository(testFileName);
            SolarPanelService        service = new SolarPanelService(repo);

            //act
            service.Create(panel);
            SolarPanelResult result = service.Update(upatePanel);

            //assert
            Assert.IsFalse(result.Success);
            Assert.AreEqual("Date Installed cannot be in the future", result.Message);
            Assert.IsNull(result.Data);
            Assert.AreEqual(1, repo.ReadAll().Count);
            Assert.AreEqual(panel, service.ReadSinglePanel("TestSection", 8, 8).Data);
            File.Delete(testFileName);
        }
Exemplo n.º 12
0
        public void UpdateShouldUpdateToEnteredPanel()
        {
            //arrange
            string testFile            = "TestDataUpdate.csv";
            ISolarPanelRepository repo = new FileSolarPanelRepository(testFile);

            SolarPanel panel = new SolarPanel
            {
                Section       = "Main",
                Row           = 1,
                Column        = 1,
                DateInstalled = DateTime.Parse("02/06/2018"),
                Material      = MaterialType.CopperIndiumGalliumSelenide,
                IsTracking    = false
            };

            //act
            repo.Update($"Main-1-1", panel);
            Dictionary <string, SolarPanel> panelList = repo.ReadAll();

            //assert
            Assert.AreEqual(panelList["Main-1-1"], panel);
        }
Exemplo n.º 13
0
        public void ReadSinglePanelShouldReturnGivenPanelIfPresent()
        {
            //arrange
            FileSolarPanelRepository repo    = new FileSolarPanelRepository("TestDataBLLRead.csv");
            SolarPanelService        service = new SolarPanelService(repo);
            SolarPanel resultingPanel;
            SolarPanel existingPanel = new SolarPanel
            {
                Section       = "Test1",
                Row           = 50,
                Column        = 2,
                DateInstalled = DateTime.Parse("02 / 05 / 2020"),
                Material      = MaterialType.AmorphousSilicon,
                IsTracking    = false
            };
            SolarPanelResult result = new SolarPanelResult();

            //act
            result         = service.ReadSinglePanel("Test1", 50, 2);
            resultingPanel = result.Data;

            //assert
            Assert.AreEqual(existingPanel, resultingPanel);
        }