public void QueryDevice_BadInputs()
        {
            var device = _captainHookGenerator.GenerateQueryDevice();

            device.category = "";
            Assert.Throws <ArgumentException>(() => _service.ValidateForStockQuery(device));

            device = _captainHookGenerator.GenerateQueryDevice();
            device.address.PostalCode = "";
            Assert.Throws <ArgumentException>(() => _service.ValidateForStockQuery(device));
        }
Exemplo n.º 2
0
        public async Task Test_ChangeDeviceInformation_NotPossible()
        {
            //Take the device from the inserted offer and change attributes that cannot be updated
            Device device           = _offer.devices[0];
            var    categoryOriginal = device.category;
            var    idOriginal       = device.id;

            device.category = "Doch was anderes";
            device.id       = 999999;

            //Try to update
            var changedRows = await _resourceStockUpdateService.ChangeInformationAsync(_token, device);

            Assert.True(changedRows == 0);

            //The original device should still be findable
            Device queryDevice = _captainHookGenerator.GenerateQueryDevice();
            var    response    = await _resourceStockQueryService.QueryOffersAsync(queryDevice, "de")
                                 .ToListAsync();

            //Assert
            Assert.NotNull(response);
            Assert.NotEmpty(response);
            var deviceFromQuery = response.First().resource;

            Assert.Equal(categoryOriginal, deviceFromQuery.category);
            Assert.True(deviceFromQuery.id == idOriginal);
        }
Exemplo n.º 3
0
        public async Task Test_DeleteDevice_CompareQueryMethods()
        {
            var device = _offerCaptainHook.devices[0];

            //Mark as deleted
            await _resourceStockUpdateService.MarkDeviceAsDeletedAsync(_tokenCaptainHook, device.id, "A reason");

            //Device should not be retrieved by querying the link
            var foundOffer = await _resourceStockQueryService.QueryLinkAsync(_tokenCaptainHook);

            Assert.NotNull(foundOffer);
            Assert.Empty(foundOffer.devices);

            //Device should not be retrieved by querying with a device object
            var deviceForQuery = _captainHookGenerator.GenerateQueryDevice();
            var foundDevices   = await _resourceStockQueryService.QueryOffersAsync(deviceForQuery, "de").ToListAsync();

            Assert.NotNull(foundDevices);
            Assert.Empty(foundDevices);

            //Find method should return the device nevertheless
            var foundDevice = await _resourceStockQueryService.FindAsync(new DeviceEntity(), device.id);

            Assert.NotNull(foundDevice);
        }
Exemplo n.º 4
0
        public void QueryDevice_BadInputs()
        {
            //Invalid category
            var device = _captainHookGenerator.GenerateQueryDevice();

            device.category = "";
            Assert.Throws <ArgumentException>(() => _service.ValidateForDemandQuery(device));

            //Country empty but postal code specified
            device = _captainHookGenerator.GenerateQueryDevice();
            device.address.Country = "";
            Assert.Throws <ArgumentException>(() => _service.ValidateForDemandQuery(device));

            //Negative kilometer
            device           = _captainHookGenerator.GenerateQueryDevice();
            device.kilometer = -10;
            Assert.Throws <ArgumentException>(() => _service.ValidateForDemandQuery(device));
        }
Exemplo n.º 5
0
        public async Task InsertOffer_QueryOfferElements_DeleteOffer()
        {
            //Insert the offer
            var offer = _captainHookGenerator.generateOffer();
            var token = await _resourceStockUpdateService.InsertAsync(offer, "de");

            Assert.True(token.Length == 30);

            //Query the link
            var entity = await _resourceStockQueryService.QueryLinkAsync(token);

            Assert.Equal(offer.provider.name, entity.provider.name);

            //Now query the elements. If it is not empty we received the element back

            //Get device
            var queryDevice   = _captainHookGenerator.GenerateQueryDevice();
            var resultDevices = await _resourceStockQueryService.QueryOffersAsync(queryDevice, "de")
                                .ToListAsync();

            Assert.NotNull(resultDevices);
            Assert.NotEmpty(resultDevices);
            var deviceFromQuery = resultDevices.First().resource;
            var deviceOriginal  = offer.devices.First();

            Console.Out.WriteLine(deviceFromQuery);
            Console.Out.WriteLine(deviceOriginal);
            Assert.Equal(deviceOriginal, deviceFromQuery);

            //check the provider
            var providerFromQuery = resultDevices.First().provider;
            var providerOriginal  = offer.provider;

            Console.Out.WriteLine(providerFromQuery);
            Console.Out.WriteLine(providerOriginal);
            // ---- HOTFIX
            // Vorerst sollen keine persönliche Daten veröffentlicht werden.
            // Assert.True(providerOriginal.Equals(providerFromQuery));

            //Get consumable
            var queryConsumable   = _captainHookGenerator.GenerateQueryConsumable();
            var resultConsumables = await _resourceStockQueryService.QueryOffersAsync(queryConsumable, "de")
                                    .ToListAsync();

            Assert.NotNull(resultConsumables);
            Assert.NotEmpty(resultDevices);
            var consumableFromQuery = resultConsumables.First().resource;
            var consumableOriginal  = offer.consumables.First();

            Console.Out.WriteLine(consumableFromQuery);
            Console.Out.WriteLine(consumableOriginal);
            Assert.Equal(consumableOriginal, consumableFromQuery);

            //Get personal
            var manpowerQuery  = _captainHookGenerator.GenerateQueryManpower();
            var resultPersonal = await _resourceStockQueryService.QueryOffersAsync(manpowerQuery, "de")
                                 .ToListAsync();

            Assert.NotNull(resultPersonal);
            Assert.NotEmpty(resultPersonal);
            var personal = resultPersonal.First();

            Assert.Equal(offer.personals.First().area, personal.resource.area);
            Assert.Equal(offer.personals.First().qualification, personal.resource.qualification);

            //Delete the offer and check if it worked
            var exception = await Record.ExceptionAsync(() => _resourceStockUpdateService.DeleteAsync(token));

            Assert.Null(exception);

            //Offer should be not available anymore
            await Assert.ThrowsAsync <DataNotFoundException>(async() => await _resourceStockQueryService.QueryLinkAsync(token));
        }