/
AGlavinskaya
/
Lab2
Обзор
Документация
Войти
/
AGlavinskaya
/
Lab2
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
LabTests/UnitTest1.cs
131 строка
4 KB
AGlavinskaya
написание функции
27 ноя 2024, 07:33
27 ноя 2024, 07:33
1cb9a04
Код
Авторство
О чём код?
using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using Model; using PracticeLogic; using ConsoleApp1; using System.Collections.Generic; using System.Security.Principal; using System.IO; using System.Linq; namespace LabTests { [TestClass] public class UnitTest1 { [TestMethod] public void MakeMeasurement_RightString() { Logic logic = new Logic(); string[] words = { "Измерение1", "2012.12.12", "\"Красноярский", "край\"", "12,5" }; Measurement measurementResult = logic.MakeMeasurement(words); ; Measurement measurement = new Measurement() { m_keyOfObject = "Измерение1", m_date = DateTime.ParseExact("2012.12.12", "yyyy.MM.dd", null), m_place = "\"Красноярский край\" ", m_temperature = 12.5 }; Assert.ReferenceEquals(measurement, measurementResult); } [TestMethod] public void MakeClients_RightString() { Logic logic = new Logic(); string[] words = { "Измерение2", "2012.12.12", "\"Красноярский", "край\"", "12,5", "Павлов"}; ClientsMeasurement measurementResult = logic.MakeClients(words); ClientsMeasurement measurement = new ClientsMeasurement() { m_keyOfObject = "Измерение2", m_date = DateTime.ParseExact("2012.12.12", "yyyy.MM.dd", null), m_place = "\"Красноярский край\" ", m_temperature = 12.5, m_ClientSurname = "Павлов" }; Assert.ReferenceEquals(measurement, measurementResult); } [TestMethod] public void MakeStandart_RightString() { Logic logic = new Logic(); string[] words = { "Измерение3", "2012.12.12", "\"Красноярский", "край\"", "12,5", "3" }; MeasurementStandart measurementResult = logic.MakeStandart(words); MeasurementStandart measurement = new MeasurementStandart() { m_keyOfObject = "Измерение2", m_date = DateTime.ParseExact("2012.12.12", "yyyy.MM.dd", null), m_place = "\"Красноярский край\" ", m_temperature = 12.5, m_standart = 3 }; Assert.ReferenceEquals (measurement, measurementResult); } [TestMethod] public void MakeMeasurement_ThrowsFormatException() { Logic logic = new Logic(); string[] words = { "Измерение1", "2024.06.01" }; Assert.ThrowsException<FormatException>(() => logic.MakeMeasurement(words)); } [TestMethod] public void MakeClients_ThrowsFormatException() { Logic logic = new Logic(); string[] words = { "Измерение2", "2021.06.01", "12,5" }; Assert.ThrowsException<FormatException>(() => logic.MakeClients(words)); } [TestMethod] public void MakeStandart_ThrowsFormatException() { Logic logic = new Logic(); string[] words = { "Измерение3", "12,5" }; Assert.ThrowsException<FormatException>(() => logic.MakeStandart(words)); } [TestMethod] public void ParseFile_FileNotFound_ThrowsException() { Logic logic = new Logic(); Assert.ThrowsException<FileNotFoundException>(() => logic.ParseFile()); } [TestMethod] public void NewTest1() { Logic logic = new Logic(); string str = "4-0803295-20"; int count = 3; Assert.AreEqual(logic.Zeros(str), count); } [TestMethod] public void NewTest2() { Logic logic = new Logic(); string str = ""; Assert.ThrowsException<Exception>(() => logic.Zeros(str)); } [TestMethod] public void NewTest3() { Logic logic = new Logic(); string str = "nacdLKFijowgr"; Assert.AreEqual(logic.Zeros(str), 0); } } }