public MowerSession MowerPosition(int x, int y, MowerSession session)
        {
            // This makes sure that the user doesn't send back negetive numbers
            // and if this happens then they are informed in the object that this isn't
            // an accepted format
            if (x <= 0 || y <= 0)
            {
                session.Error = "Positive numbers only";
            }

            if (session.Width <= 0 || session.Height <= 0)
            {
                session.Error = "Please set the width and height of the lawn";
            }

            // This sets up the position of the mower on the X and Y position
            // while making a call to the clamp method to make sure that it does
            // not go below the min width and height or beyond the width or height
            // of the lawn
            session.PositionX = Clamp(x, minWidth, session.Width);
            session.PositionY = Clamp(y, minHeight, session.Height);


            // This accesses the status string section of the object, makes a call to the mower status method
            // and then sends back the appropriate debug information to be outputted by the client
            session.Status = MowerStatus("set the position of the mower", session);

            // This sends back the object
            return(session);
        }
        public MowerSession LawnDimensions(int x, int y)
        {
            // This creates a new mowersession object to send back to the client applications
            MowerSession session = new MowerSession();

            // This makes sure that the user doesn't send back negetive numbers
            // and if this happens then they are informed in the object that this isn't
            // an accepted format
            if (x <= 0 || y <= 0)
            {
                session.Error = "Positive numbers only";
            }

            // This sets up the width and height of the lawn
            session.Width  = x;
            session.Height = y;

            // This set up the X and Y positon as the minimum width and height of the lawn
            session.PositionX = minWidth;
            session.PositionY = minHeight;

            // This accesses the status string section of the object, makes a call to the mower status method
            // and then sends back the appropriate debug information to be outputted by the client
            session.Status = MowerStatus(string.Format("set the dimensions of the lawn. {0} {1}",
                                                       session.Width, session.Height), session);

            // This sends back the object
            return(session);
        }
        public void MoveDown()
        {
            // This section details with the intial setup of the test
            SLMMController controller = new SLMMController();
            MowerSession   postback   = controller.LawnDimensions(10, 10);
            MowerSession   session    = controller.MoveDown(postback);

            // This check is to make sure that the user moves to the correct position
            Assert.AreEqual(session.PositionX, 1);
            Assert.AreEqual(session.PositionY, 2);
        }
        public void MoveUp()
        {
            // This section details with the intial setup of the test
            SLMMController controller = new SLMMController();
            MowerSession   postback   = controller.LawnDimensions(10, 10);
            MowerSession   session    = controller.MoveUp(postback);

            // This tests for two things first it makes sure that the method comes back with the correct
            // information but it is also check to see if the clamp method in the controller is making
            // sure that the mower does not go out of bounds
            Assert.AreEqual(session.PositionX, 1);
            Assert.AreEqual(session.PositionY, 1);
        }
        public void LawnDimensions()
        {
            // This section details with the intial setup of the test
            SLMMController controller = new SLMMController();
            MowerSession   session    = controller.LawnDimensions(10, 10);

            //This assert checks to see if the width entered intially in the method is the same width that comes
            // out
            Assert.AreEqual(10, session.Width);

            // This assert checks to see if the height entered initially in the method is the same height that comes
            // out
            Assert.AreEqual(10, session.Height);
        }
        // This method creates the output messages
        private string MowerStatus(string action, MowerSession session)
        {
            // This is sleep time for thread, I've set it as 1000 as stated in the document and
            // made it const so that it's can be changed further down the line
            const int threadSleepTime = 1000;

            // This is the method that actually puts the program to sleep
            // it's there to simulate latency on a network
            Thread.Sleep(threadSleepTime);

            // I used the Format method to cleanly construct the string
            return(string.Format("Time: {0} - Action: {1} - Position: X {2}, Y {3}.",
                                 DateTime.Now.ToString("HH:mm:ss"), action, session.PositionX, session.PositionY));
        }
        public void MowerPosition()
        {
            // This section details with the intial setup of the test
            SLMMController controller = new SLMMController();
            MowerSession   postback   = controller.LawnDimensions(10, 10);

            MowerSession session = controller.MowerPosition(2, 5, postback);

            // This checks to see if the actual Position X given initally is the same
            // as the one that is actually assigned
            Assert.AreEqual(2, session.PositionX);

            // This checks to see if the actual Position Y given initally is the same
            // as the one that is actually assigned
            Assert.AreEqual(5, session.PositionY);
        }
        public MowerSession MoveLeft(MowerSession session)
        {
            // This makes sure that the width of the session is set
            if (session.Width <= 0)
            {
                session.Error = "Please set the width and height of the lawn";
            }

            // This moves the lawn mower left by one
            session.PositionX--;

            // This makes sure that the mower doesn't go beyond the min width or the lawn width
            session.PositionX = Clamp(session.PositionX, minWidth, session.Width);


            // This accesses the status string section of the object, makes a call to the mower status method
            // and then sends back the appropriate debug information to be outputted by the client
            session.Status = MowerStatus("moved the mower left by one", session);

            return(session);
        }
        public MowerSession MoveDown(MowerSession session)
        {
            // This makes sure that the height of the session is set
            if (session.Height <= 0)
            {
                session.Error = "Please set the width and height of the lawn";
            }

            // This moves the lawn mower down by one
            session.PositionY++;

            // This makes sure that it doesn't go beyond the min height or the lawn height
            session.PositionY = Clamp(session.PositionY, minHeight, session.Height);


            // This accesses the status string section of the object, makes a call to the mower status method
            // and then sends back the appropriate debug information to be outputted by the client
            session.Status = MowerStatus("moved the mower down by one", session);

            // This sends back the object
            return(session);
        }