lundi 23 novembre 2015

Why am I getting a cannot implicitly convert int to bool error?

I don't understand why its saying that I'm trying to convert a int to a bool. It may be a simple problem but its going over my head. Can anyone see my issue. I am getting my error in my Unit Test on the "if (dao.Update(call))" and "if (vm.Update())". It says I cannot implicitly convert int to bool. Could it be my Update method for my DAO and ViewModel? Thanks in advance for anyone who can help me out. Cheers.

Here is my entity class:

public class Call : IMongoEntity
    {
        public ObjectId _id { get; set; }
        public string _accessId { get; set; }
        public ObjectId EmployeeId { get; set; }
        public ObjectId ProblemId { get; set; }
        public ObjectId TechId { get; set; }
        public System.DateTime DateOpened { get; set; }
        public System.DateTime? DateClosed { get; set; }
        public bool OpenStatus { get; set; }
        public string Notes { get; set; }
    }

Here is my DAO Code:

public int Update(Call call)
        {
            int updateOK = -1;
            try
            {
                DbContext ctx = new DbContext();
                ctx.Save<Call>(call, "calls");
                updateOK = 1;
            }
            catch (MongoConcurrencyException ex)
            {
                updateOK = -2;
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Problem " + ex.Message);
                DALUtils.ErrorRoutine(ex, "CallDAO", "Update");
            }
            return updateOK;
        }

Here is my ViewModel Code:

public int Update()
        {
            int rowsUpdated = -1;
            try
            {
                Call call = new Call();
                call.DateOpened = DateOpened;
                call.DateClosed = DateClosed;
                call.OpenStatus = OpenStatus;
                call.Notes = Notes;
                rowsUpdated = _dao.Update(call);
            }
            catch (Exception ex)
            {
                ViewModelsUitls.ErrorRoutine(ex, "CallViewModel", "Update");
            }
            return rowsUpdated;
        }

And here's my Unit Testing Code for the DAO and ViewModel:

[TestMethod]
        public void CallDAOComprehensiveTestsReturnTrue()
        {
            CallDAO dao = new CallDAO();
            Call call = new Call();
            call.DateOpened = DateTime.Now;
            call.DateClosed = null;
            call.OpenStatus = true;
            call.EmployeeId = new MongoDB.Bson.ObjectId("56527d3e3e400c1adc33ad37"); // bigshot
            call.TechId = new MongoDB.Bson.ObjectId("56527d3e3e400c1adc33ad3d"); // Burner
            call.ProblemId = new MongoDB.Bson.ObjectId("56527d3e3e400c1adc33ad44");//memory
            call.Notes = "Bigshot has bad RAM, Burner to fix it";
            string newId = dao.Create(call);
            this.testContextInstance.WriteLine("New Call Id == " + newId);
            call = dao.GetById(newId);
            this.testContextInstance.WriteLine("Call retrieved");
            call.Notes = call.Notes + "\nOrdered new Ram";

            if (dao.Update(call))
                this.testContextInstance.WriteLine("Call was updated " + call.Notes);
            else
                Trace.WriteLine("Call was not updated");

            if (dao.Delete(newId))
                this.testContextInstance.WriteLine("call was deleted");
            else
                this.testContextInstance.WriteLine("call was not deleted");
            call = dao.GetById(newId);
            Assert.IsNull(call);
        }

        [TestMethod]
        [ExpectedException(typeof(MongoDB.Driver.MongoException),"No Id exists")]
        public void CallViewModelComprehensiveTestsReturnTrue()
        {
            CallViewModel vm = new CallViewModel();
            vm.DateOpened = DateTime.Now;
            vm.OpenStatus = true;
            vm.EmployeeId = "56527d3e3e400c1adc33ad37"; // Bigshot
            vm.TechId = "56527d3e3e400c1adc33ad3d"; // Burner
            vm.ProblemId = "56527d3e3e400c1adc33ad44"; // memory
            vm.Notes = "Bigshot has ban RAM, Burner to fix it";
            vm.Create();
            this.testContextInstance.WriteLine("New call Id == " + vm.Id);
            vm.GetById(vm.Id);
            this.testContextInstance.WriteLine("Call retrieved");
            vm.Notes = vm.Notes + "\nOrdered new Ram";

            if (vm.Update())
                this.testContextInstance.WriteLine("Call was updated " + vm.Notes);
            else
                Trace.WriteLine("Call was not updated");

            if (vm.Delete(vm.Id))
                this.testContextInstance.WriteLine("Call was deleted");
            else
                this.testContextInstance.WriteLine("Call was not deleted");

            vm.Update(); // should throw MongoException see attribute
        }

Aucun commentaire:

Enregistrer un commentaire