Beispiel #1
0
        public void UpdateViolatingPlanes_Calls_AddToLog_withCorrectArgs_WhenNewViolationFound()
        {
            // Make sure airspace always returns true so all given planes will be passed to UpdateViolatingPlanes()
            _airspace.IsWithinArea(0, 0, 0).ReturnsForAnyArgs(true);


            // Create dummyPlanes
            IPlane plane1 = GetDummyIPlane();
            IPlane plane2 = GetDummyIPlane();

            List <List <IPlane> > planeVIolationList = new List <List <IPlane> >();
            List <IPlane>         planePair          = new List <IPlane> {
                plane1, plane2
            };

            planeVIolationList.Add(planePair);


            _planeSeparation.CheckPlanes(Arg.Any <List <IPlane> >()).Returns(planeVIolationList);



            // Just to run code parameter does not matter
            uut.UpdatePlaneList(new List <IPlane>());      // First time should run addToLog since planes is new
            uut.UpdatePlaneList(new List <IPlane>());      // Second time nothing should happen sinces planes already exists

            // Get all _loggers Received calls from AddToLog where string argument matched
            // Code example found at: https://stackoverflow.com/questions/52439697/how-to-check-any-of-multiple-overloads-called-nsubstitute
            // Answer posted by: David Tchepak sep 22'18
            var calls = _logger.ReceivedCalls()
                        .Where(x => x.GetMethodInfo().Name == nameof(_logger.AddToLog))
                        .Where(x => ((string)x.GetArguments()[0]).Contains("Violates Separation condition!"));

            // Check if number of expected arguments was found
            Assert.AreEqual(1, calls.Count());
        }
Beispiel #2
0
        public void Init()
        {
            _logger    = NSubstitute.Substitute.For <ILogger>();
            _airspace  = NSubstitute.Substitute.For <IAirspace>();
            _rendition = Substitute.For <IRendition>();

            _planeSeparation = Substitute.For <IPlaneSeparation>();
            _planeSeparation.CheckPlanes(Arg.Any <List <IPlane> >()).Returns(new List <List <IPlane> >());



            // Todo: delete comment
            //_planeSeparation = new PlaneSeparation( 500, 3000 );

            // Air Traffic Monitor
            uut = new ATM(_airspace, _planeSeparation, _rendition, _logger);
        }