public string TestAirConditioner(string manufacturer, string model)
        {
            IAirConditioner airConditioner = this.Database.AirConditioners.GetItem(manufacturer, model);
            var             mark           = airConditioner.Test() ? Mark.Passed : Mark.Failed;

            this.Database.Reports.Add(new Report(airConditioner.Manufacturer, airConditioner.Model, mark));
            return(string.Format(Constants.TestAirConditioner, model, manufacturer));
        }
        public string TestAirConditioner(string manufacturer, string model)
        {
            IAirConditioner airConditioner = database.GetAirConditioner(manufacturer, model);

            if (airConditioner == null)
            {
                throw new NonExistantEntryException();
            }
            Mark mark = (Mark)airConditioner.Test();

            database.AddReport(new Report(airConditioner.Manufacturer, airConditioner.Model, mark));
            return(string.Format(Constants.TEST, model, manufacturer));
        }
Пример #3
0
        public void TestAirConditioner(string manufacturer, string model)
        {
            try
            {
                IAirConditioner airConditioner = this.data.GetAirConditioner(manufacturer, model);

                bool isPassed = airConditioner.Test();

                if (isPassed)
                {
                    airConditioner.Mark = "Passed";
                }

                IReport report = new Report(
                    airConditioner.Manufacturer,
                    airConditioner.Model,
                    airConditioner.Mark);

                foreach (var rep in data.Reports)
                {
                    if (rep.Manufacturer == airConditioner.Manufacturer &&
                        rep.Model == airConditioner.Model)
                    {
                        throw new DuplicateEntryException("An entry for the given model already exists.");
                    }
                }

                data.AddReport(report);
                writer.WriteLine(
                    $"Air conditioner model {airConditioner.Model}" +
                    $" from {airConditioner.Manufacturer} tested successfully");
            }
            catch (DuplicateEntryException e)
            {
                writer.WriteLine(e.Message);
            }
            catch (NullReferenceException)
            {
                writer.WriteLine("The specified entry does not exist.");
            }
        }