Example #1
0
        public void TestProcessing3dand2dAssets()
        {
            var job = serviceProvider.GetService <IJob>();

            Assert.IsNotNull(job);

            var subscription = new AssetUpdateSubscriptionModel()
            {
                ProjectUid          = Guid.Parse("7842662B-F8E5-4752-A64B-261CE7EDA152"),
                CustomerUid         = Guid.Parse("8BB0D3A3-A755-4AD9-A4FA-999D6C1C104C"),
                AuthorizationHeader = "TEST AUTH",
                JWTAssertion        = "TEST JWT"
            };

            var assetUid = "47C03885-4845-4637-90B5-4CCE5D8DA040";

            var machine = new MachineStatus(55743,
                                            "Test Machine from 3d",
                                            true,
                                            "LAST DESIGN FROM 3D",
                                            15215,
                                            new DateTime(2018, 1, 2, 3, 4, 5, DateTimeKind.Utc),
                                            0.59915074193701334, // radians
                                            -1.470376021323053,  // radians
                                            null,
                                            null,
                                            Guid.Parse(assetUid));

            var machineResult = new Machine3DStatuses(ContractExecutionStatesEnum.ExecutedSuccessfully);

            machineResult.MachineStatuses.Add(machine);

            var assetDetails = new AssetDetails()
            {
                AssetId  = "55743 - test",
                AssetUid = assetUid,
                LastReportedLocationLatitude  = 123.45d,
                LastReportedLocationLongitude = 43.1d,
                LastLocationUpdateUtc         = machine.lastKnownTimeStamp.Value.AddSeconds(1),
                FuelLevelLastReported         = 2.1d,
                LastPercentFuelRemainingUtc   = new DateTime(2019, 1, 1, 23, 41, 23, DateTimeKind.Utc)
            };

            var expectedResult = new AssetAggregateStatus()
            {
                CustomerUid            = subscription.CustomerUid,
                ProjectUid             = subscription.ProjectUid,
                LocationLastUpdatedUtc = assetDetails.LastLocationUpdateUtc.ToUniversalTime(),
                AssetUid  = Guid.Parse(assetUid),
                Design    = machine.lastKnownDesignName,
                FuelLevel = assetDetails.FuelLevelLastReported,
                FuelLevelLastUpdatedUtc = assetDetails.FuelReportedTimeUtc,
                Latitude        = assetDetails.LastReportedLocationLatitude,
                Longitude       = assetDetails.LastReportedLocationLongitude,
                LiftNumber      = 15215,
                AssetIdentifier = "55743 - test", // will take this from the 2d data, as a higher priority that the 3d machine name
                MachineName     = "Test Machine from 3d"
            };

            var expectedHeaders = GetExpectedHeaders(subscription.CustomerUid, subscription.AuthorizationHeader, subscription.JWTAssertion);
            AssetAggregateStatus resultStatus = null; // Keep a reference to the event generated for comparasion

            // Setup the returns
            mockAssetStatusServerHubClient
            .Setup(m => m.GetSubscriptions())
            .Returns(Task.FromResult(new List <AssetUpdateSubscriptionModel> {
                subscription
            }));

            mockProductivity3dV2ProxyNotification.Setup(m =>
                                                        m.ExecuteGenericV2Request <Machine3DStatuses>(
                                                            It.IsAny <string>(),
                                                            It.IsAny <HttpMethod>(),
                                                            It.IsAny <Stream>(),
                                                            It.IsAny <IHeaderDictionary>()))
            .Returns(Task.FromResult(machineResult));

            mockFleetAssetDetails
            .Setup(m => m.GetAssetDetails(
                       It.IsAny <string>(),
                       It.IsAny <IHeaderDictionary>()))
            .Returns(Task.FromResult(assetDetails));

            mockAssetStatusServerHubClient
            .Setup(m => m.UpdateAssetLocationsForClient(It.IsAny <AssetAggregateStatus>()))
            .Returns(Task.FromResult(true))
            .Callback <AssetAggregateStatus>((e) => { resultStatus = e; });

            // Run the test
            job.Run(null).Wait();

            // Validate the calls
            // We should have this called for our asset uid which matched to the 3d asset id
            mockFleetAssetDetails
            .Verify(m => m.GetAssetDetails(
                        It.Is <string>(s => Guid.Parse(s) == Guid.Parse(assetDetails.AssetUid)),
                        It.Is <IHeaderDictionary>(d => DictionaryContentEquals(d, expectedHeaders))),
                    Times.Once);

            // We should have received one event
            mockAssetStatusServerHubClient
            .Verify(m =>
                    m.UpdateAssetLocationsForClient(It.IsAny <AssetAggregateStatus>()),
                    Times.Once());

            // Validate it is the expected result
            Assert.IsNotNull(resultStatus);
            resultStatus.Should().BeEquivalentTo(expectedResult);
        }
Example #2
0
        public void TestProcessing3dAssetsOnly()
        {
            var job = serviceProvider.GetService <IJob>();

            Assert.IsNotNull(job);

            var subscription = new AssetUpdateSubscriptionModel()
            {
                ProjectUid          = Guid.Parse("038A3ACB-C985-4E3A-AB98-FF3C939B30BF"),
                CustomerUid         = Guid.Parse("12DCFAF5-96A4-4E27-BE53-28A226A7AAB6"),
                AuthorizationHeader = "TEST AUTH",
                JWTAssertion        = "TEST JWT"
            };

            var machine1 = new MachineStatus(123,
                                             "Test Machine1",
                                             true,
                                             "LAST DESIGN 1",
                                             6433,
                                             new DateTime(2010, 1, 2, 3, 4, 5, DateTimeKind.Utc),
                                             0.59915074193701334, // radians
                                             -1.470376021323053,  // radians
                                             null,
                                             null);

            var machineResult = new Machine3DStatuses(ContractExecutionStatesEnum.ExecutedSuccessfully);

            machineResult.MachineStatuses.Add(machine1);

            var expectedResult = new AssetAggregateStatus()
            {
                AssetIdentifier        = "Test Machine1",
                LiftNumber             = 6433,
                CustomerUid            = subscription.CustomerUid,
                ProjectUid             = subscription.ProjectUid,
                LocationLastUpdatedUtc = machine1.lastKnownTimeStamp,
                AssetUid  = null,
                Design    = machine1.lastKnownDesignName,
                FuelLevel = null,
                FuelLevelLastUpdatedUtc = null,
                Latitude    = machine1.lastKnownLatitude * RADIANS_TO_DEGREES,
                Longitude   = machine1.lastKnownLongitude * RADIANS_TO_DEGREES,
                MachineName = "Test Machine1"
            };

            var expectedHeaders = GetExpectedHeaders(subscription.CustomerUid, subscription.AuthorizationHeader, subscription.JWTAssertion);
            AssetAggregateStatus resultStatus = null; // Keep a reference to the event generated for comparasion

            // Setup the returns
            mockAssetStatusServerHubClient
            .Setup(m => m.GetSubscriptions())
            .Returns(Task.FromResult(new List <AssetUpdateSubscriptionModel> {
                subscription
            }));

            mockProductivity3dV2ProxyNotification.Setup(m =>
                                                        m.ExecuteGenericV2Request <Machine3DStatuses>(
                                                            It.IsAny <string>(),
                                                            It.IsAny <HttpMethod>(),
                                                            It.IsAny <Stream>(),
                                                            It.IsAny <IHeaderDictionary>()))
            .Returns(Task.FromResult(machineResult));

            mockAssetStatusServerHubClient
            .Setup(m => m.UpdateAssetLocationsForClient(It.IsAny <AssetAggregateStatus>()))
            .Returns(Task.FromResult(true))
            .Callback <AssetAggregateStatus>((e) => { resultStatus = e; });

            // Run the test
            job.Run(null).Wait();

            // Validate the calls

            // CCSSSCON-85 not possible with WM devices
            //// We should not call this if we have not matching 3d/2d assets
            //mockAssetResolverProxy
            //  .Verify(m => m.GetMatching3D2DAssets(It.IsAny<MatchingAssetsDisplayModel>(),
            //      It.IsAny<IHeaderDictionary>()),
            //    Times.Never);

            // We should have received one event
            mockAssetStatusServerHubClient
            .Verify(m =>
                    m.UpdateAssetLocationsForClient(It.IsAny <AssetAggregateStatus>()),
                    Times.Once());

            // Validate it is the expected result
            Assert.IsNotNull(resultStatus);
            resultStatus.Should().BeEquivalentTo(expectedResult);
        }