public void Test_switchOnOff_beacon()
        {
            // Arrange
            uint[] seq = new uint[] { 1, 2, 3, 4, 5 };
            beacon obj;
            int    expectedSignalOff = 0;
            int    expectedSignalOn1 = 5;
            int    expectedSignalOn2 = 4;

            // Act
            obj = new beacon(seq);
            int signalOff1 = obj.emitSignal();

            obj.switchOnOff();
            int signalOn1 = obj.emitSignal();

            obj.switchOnOff();
            int signalOff2 = obj.emitSignal();

            obj.switchOnOff();
            int signalOn2 = obj.emitSignal();

            // Assert
            Assert.AreEqual(expectedSignalOff, signalOff1);
            Assert.AreEqual(expectedSignalOn1, signalOn1);
            Assert.AreEqual(expectedSignalOff, signalOff2);
            Assert.AreEqual(expectedSignalOn2, signalOn2);
        }
        public void Test_emitSignal_beacon()
        {
            // Arrange
            uint[] seq = new uint[] { 1, 4, 3, 2, 5, 0, 1, 2 };
            beacon obj;
            int    expectedSignalOff        = 0;
            int    expectedSignal1          = 5;
            int    expectedSignal2          = 4;
            int    expectedSignal3          = 3;
            int    expectedSignal4          = 2;
            int    expectedSignal5          = 1;
            int    expectedSignalNotCharged = 0;

            // Act
            obj = new beacon(seq);
            int signalOff = obj.emitSignal();

            obj.switchOnOff();
            int signal1          = obj.emitSignal();
            int signal2          = obj.emitSignal();
            int signal3          = obj.emitSignal();
            int signal4          = obj.emitSignal();
            int signal5          = obj.emitSignal();
            int signalNotCharged = obj.emitSignal();

            // Assert
            Assert.AreEqual(expectedSignalOff, signalOff);
            Assert.AreEqual(expectedSignal1, signal1);
            Assert.AreEqual(expectedSignal2, signal2);
            Assert.AreEqual(expectedSignal3, signal3);
            Assert.AreEqual(expectedSignal4, signal4);
            Assert.AreEqual(expectedSignal5, signal5);
            Assert.AreEqual(expectedSignal1, signal1);
            Assert.AreEqual(expectedSignalNotCharged, signalNotCharged);
        }
示例#3
0
        public void Test_beacon_StateFns()
        {
            // Arrange
            beacon bc = new beacon();

            int[] testArray   = new int[] { 1, 2, 3, 4, 5 };
            int[] signalArray = new int[5];
            int[] assertArray = new int[] { 1, 0, 2, 0, 3 };

            // Act
            bc.setSeq(testArray);
            for (int i = 0; i < signalArray.Length; i++)
            {
                if (i % 2 == 0)
                {
                    bc.turnOn();
                }
                else
                {
                    bc.turnOff();
                }
                signalArray[i] = bc.signal();
            }

            // Assert
            CollectionAssert.AreEqual(signalArray, assertArray);
        }
        public void Test_resetToOrigSeq_beacon()
        {
            // Arrange
            uint[] seq1 = new uint[] { 1, 2, 3, 4, 5 };
            uint[] seq2 = new uint[] { 6, 7, 8, 9, 10 };
            beacon obj;
            int    expectedSignal1 = 5;
            int    expectedSignal2 = 10;
            int    expectedSignal3 = 5;

            // Act
            obj = new beacon(seq1);
            obj.switchOnOff();
            int signal1 = obj.emitSignal();

            obj.newSeq(seq2);
            int signal2 = obj.emitSignal();

            obj.resetToOrigSeq();
            int signal3 = obj.emitSignal();

            // Assert
            Assert.AreEqual(expectedSignal1, signal1);
            Assert.AreEqual(expectedSignal2, signal2);
            Assert.AreEqual(expectedSignal3, signal3);
        }
        // PUT api/beacon/5
        public HttpResponseMessage Putbeacon(string id, beacon beacon)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != beacon.beaconid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            db.Entry(beacon).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        // GET api/beacon/5
        public beacon Getbeacon(string id)
        {
            beacon beacon = db.beacon.Find(id);

            if (beacon == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(beacon);
        }
        public void Test_whoAmI_beacon()
        {
            // Arrange
            uint[] seq = new uint[] { 1, 2, 3, 4, 5 };
            beacon obj;
            uint   expectedWhoAmI = 0;

            // Act
            obj = new beacon(seq);
            uint whoAmI = obj.whoAmI();

            // Assert
            Assert.AreEqual(expectedWhoAmI, whoAmI);
        }
        // POST api/beacon
        public HttpResponseMessage Postbeacon(beacon beacon)
        {
            if (ModelState.IsValid)
            {
                db.beacon.Add(beacon);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, beacon);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = beacon.beaconid }));
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
示例#9
0
        public void Test_beacon_SignalSetSeq()
        {
            // Arrange
            beacon bc = new beacon();

            int[] testArray   = new int[] { 1, 2, 3, 4, 5 };
            int[] signalArray = new int[5];
            int[] assertArray = new int[] { 1, 2, 3, 4, 5 };

            // Act
            bc.setSeq(testArray);
            for (int i = 0; i < signalArray.Length; i++)
            {
                signalArray[i] = bc.signal();
            }

            // Assert
            CollectionAssert.AreEqual(signalArray, assertArray);
        }
        public void Test_newSeq_beacon()
        {
            // Arrange
            uint[] origSeq         = new uint[] { 1, 2, 3, 4, 5, };
            uint[] newSeq          = new uint[] { 6, 7, 8, 9 };
            int    expectedSignal1 = 5;
            int    expectedSignal2 = 9;
            beacon obj;

            // Act
            obj = new beacon(origSeq);
            obj.switchOnOff();
            int signal1 = obj.emitSignal();

            obj.newSeq(newSeq);
            int signal2 = obj.emitSignal();

            // Assert
            Assert.AreEqual(expectedSignal1, signal1);
            Assert.AreEqual(expectedSignal2, signal2);
        }
示例#11
0
        public void Test_beacon_ChargeFns()
        {
            // Arrange
            beacon bc = new beacon();

            int[] testArray   = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int[] signalArray = new int[11];
            int[] assertArray = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0 };

            // Act
            bc.setSeq(testArray);
            for (int i = 0; i < signalArray.Length; i++)
            {
                signalArray[i] = bc.signal();
            }
            bc.recharge(5);

            // Assert
            Assert.AreEqual(bc.getCharge(), 5);
            CollectionAssert.AreEqual(signalArray, assertArray);
        }
示例#12
0
        // DELETE api/beacon/5
        public HttpResponseMessage Deletebeacon(string id)
        {
            beacon beacon = db.beacon.Find(id);

            if (beacon == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.beacon.Remove(beacon);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, beacon));
        }