using Microsoft.VisualStudio.TestTools.UnitTesting;
using GFUDemo_CS;
namespace AutomobileTestProject
{
[TestClass]
public class AutomobileTest
{
[TestMethod]
public void DefaultAutomobileIsInitializedCorrectly()
{
Automobile myAuto = new Automobile();
// Заменили Assert.IsTrue на Assert.AreEqual, чтобы убрать предупреждение
Assert.AreEqual("Not specified", myAuto.Model);
Assert.AreEqual(-1, myAuto.TopSpeed);
}
[TestMethod]
public void AutomobileWithModelNameCanStart()
{
string model = "Contoso";
int topSpeed = 199;
Automobile myAuto = new Automobile(model, topSpeed);
myAuto.Start();
Assert.AreEqual(true, myAuto.IsRunning);
}
}
}
Assert.IsTrue(myAuto.IsRunning);
namespace GFUDemo_CS
{
public class Automobile
{
public string Model { get; set; }
public int TopSpeed { get; set; }
public bool IsRunning { get; set; }
// Конструктор по умолчанию
public Automobile()
{
this.Model = "Not specified";
this.TopSpeed = -1;
this.IsRunning = true;
}
// Конструктор с параметрами
public Automobile(string model, int topSpeed)
{
this.Model = model;
this.TopSpeed = topSpeed;
}
// Метод запуска
public void Start()
{
if (this.Model != "Not specified" || this.TopSpeed != -1)
{
this.IsRunning = true;
}
else
{
this.IsRunning = false;
}
}
}
}