public async Task Save_WithFileAndModel_SavesBlobToContainer()
        {
            // Arrange
            await _sut.ConfigureBlobStorage();

            var model = new WalkModel()
            {
                WalkName    = "Test walk",
                Description = "A walk in the test realm",
                SubmittedBy = "Test user"
            };

            // Act
            using (var stream = GenerateStreamFromString("a,b \n c,d"))
            {
                await _sut.Save(stream, model);
            }

            // Assert
            var blob = GetContainerReference(_containerName)
                       .GetBlockBlobReference("Test walk");

            Assert.IsTrue(await blob.ExistsAsync());
            var text = await blob.DownloadTextAsync();

            Assert.AreEqual("a,b \n c,d", text);
            await AssertMetadata(blob, "Test walk", "A walk in the test realm", "Test user");
        }
 public void ClearNewWalk()
 {
     NewWalk = new WalkModel();
     NotifyOfPropertyChange(() => NewWalk);
     NotifyOfPropertyChange(() => NewDate);
     NotifyOfPropertyChange(() => NewWalker);
     NotifyOfPropertyChange(() => NewNote);
 }
Beispiel #3
0
 public void CardSetting()
 {
     AnimalCount   = StatisticModel.AnimalsInShelterSum();
     AdoptionCount = StatisticModel.SuccessfullyAdoptedAnimals();
     PlannedWalks  = WalkModel.GetDatedWalks(DateTime.Today, DateTime.Today.AddYears(10));
     LastAnimals   = AnimalModel.LastAnimals(5);
     SetShelterInfo();
     Filter();
 }
Beispiel #4
0
 private WalkToSave MapWalkModelToWalkToSave(WalkModel walk, Uri uri)
 {
     return(new WalkToSave(walk.SubmittedBy, walk.WalkName)
     {
         Description = walk.Description,
         Location = "Local",
         SubmitterName = walk.SubmittedBy,
         WalkName = walk.WalkName,
         Url = uri.ToString()
     });
 }
        private async Task FilterData()
        {
            IsWorking = true;
            await Task.Delay(150);

            await Task.Run(() =>
            {
                AnimalWalks = WalkModel.GetAnimalDatedWalks(AnimalID, Since, To);
            });

            IsWorking = false;
        }
Beispiel #6
0
        public async Task SaveWalkAsync_WithInvalidUploadedImage_ThrowsException()
        {
            // Arrange
            var walkModel = new WalkModel
            {
                SubmittedBy = submittedBy,
                WalkName    = walkName
            };

            // Act and Assert
            Assert.ThrowsAsync <ArgumentNullException>(async() => await _target.SaveWalkAsync(walkModel));
        }
        public async Task <IActionResult> SubmitWalk(WalkModel model)
        {
            if (ModelState.IsValid)
            {
                await _assets.SaveWalkAsync(model);

                ViewBag.UserMessage = "Walk saved";
                ModelState.Clear();
            }

            return(View());
        }
        private async Task GetData()
        {
            IsWorking = true;
            await Task.Delay(150);

            await Task.Run(() =>
            {
                AnimalWalks = WalkModel.GetAnimalWalks(AnimalID);
            });

            IsWorking = false;
        }
        private async Task LoadData()
        {
            IsWorking = true;
            await Task.Delay(150);

            await Task.Run(() =>
            {
                AnimalWalks   = WalkModel.GetAnimalWalks(AnimalID);
                WalkerList    = PersonModel.ReturnWalkers();
                NewWalkerList = PersonModel.ReturnWalkers();
            });

            IsWorking = false;
        }
        private async Task LoadData()
        {
            IsWorking = true;
            await Task.Delay(150);

            await Task.Run(() =>
            {
                AdoptionList = AdoptionModel.ReturnPersonAdoptions(Person.ID);
                WalkList     = WalkModel.ReturnPersonWalks(Person.ID);
                DonationList = DonationModel.ReturnPersonDonations(Person.ID);
            });

            IsWorking = false;
        }
        public void DeleteWalk()
        {
            MessageBoxResult result = MessageBox.Show("Opravdu chcete vymazat zvolenou procházku?",
                                                      "Confirmation",
                                                      MessageBoxButton.YesNo,
                                                      MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                WalkModel.MarkAsDeleted((int)SelectedWalk.ID);

                Walk = new WalkModel();

                SelectedWalk = null;

                Filter();
            }
        }
Beispiel #12
0
        public async Task SaveWalkAsync_WithValidModel_SavesWalk()
        {
            // Arrange
            var file      = new Mock <IFormFile>();
            var walkModel = new WalkModel {
                SubmittedBy   = submittedBy,
                WalkName      = walkName,
                UploadedImage = file.Object
            };

            _storage.Setup(m => m.Save(It.IsAny <Stream>(), It.IsAny <WalkModel>())).ReturnsAsync(new Uri(storageUrl));

            // Act
            await _target.SaveWalkAsync(walkModel);

            // Assert
            _storage.Verify(m => m.Save(It.IsAny <Stream>(), It.IsAny <WalkModel>()), Times.Once);
            _tableStorage.Verify(m => m.SaveBench(It.IsAny <WalkToSave>()), Times.Once);
        }
        public async Task GetBlobs_WithContainerName_GetsBlobsFromContainer()
        {
            // Arrange
            await _sut.ConfigureBlobStorage();

            var model = new WalkModel()
            {
                WalkName    = "Test walk",
                Description = "A walk in the test realm",
                SubmittedBy = "Test user"
            };
            var otherModel = new WalkModel()
            {
                WalkName    = "Other test walk",
                Description = "A walk in the other test realm",
                SubmittedBy = "Other test user"
            };

            using (var stream = GenerateStreamFromString("a,b \n c,d"))
            {
                await _sut.Save(stream, model);
            }
            using (var stream = GenerateStreamFromString("e,f \n g,h"))
            {
                await _sut.Save(stream, otherModel);
            }

            // Act
            var blobs = await _sut.GetBlobs();

            // Assert
            Assert.AreEqual(2, blobs.Count);
            var text = await blobs[0].DownloadTextAsync();

            Assert.AreEqual("e,f \n g,h", text);
            var otherText = await blobs[1].DownloadTextAsync();

            Assert.AreEqual("a,b \n c,d", otherText);
            await AssertMetadata(blobs[1], "Other test walk", "A walk in the other test realm", "Other test user");
            await AssertMetadata(blobs[1], "Test walk", "A walk in the test realm", "Test user");
        }
Beispiel #14
0
        public async Task SaveWalkAsync(WalkModel walk)
        {
            if (walk.UploadedImage != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await walk.UploadedImage.CopyToAsync(memoryStream);

                    memoryStream.Position = 0;
                    var uri = await _storage.Save(memoryStream, walk);

                    _logger.LogInformation($"Walk: {walk.WalkName}, by: {walk.SubmittedBy} added.");
                    var entity = MapWalkModelToWalkToSave(walk, uri);
                    await _tableStorage.SaveBench(entity);
                }
            }
            else
            {
                throw new ArgumentNullException("Image", "The supplied model does not have an image");
            }
        }
Beispiel #15
0
        public async Task <Uri> Save(Stream filestream, WalkModel model)
        {
            CloudBlockBlob blockblob = _blobContainer.GetBlockBlobReference(model.WalkName);

            blockblob.Properties.ContentType = "image/jpg";

            if (!string.IsNullOrWhiteSpace(model.WalkName))
            {
                blockblob.Metadata.Add("walkname", model.WalkName);
            }
            if (!string.IsNullOrWhiteSpace(model.SubmittedBy))
            {
                blockblob.Metadata.Add("submittedby", model.SubmittedBy);
            }
            if (!string.IsNullOrWhiteSpace(model.Description))
            {
                blockblob.Metadata.Add("description", model.Description);
            }

            await blockblob.UploadFromStreamAsync(filestream);

            return(_blobContainer.GetBlockBlobReference(model.WalkName).Uri);
        }
Beispiel #16
0
        public async void Restore()
        {
            if (Since == null || To == null || (Since > To))
            {
                MessageBox.Show("Zvolte prosím platné datum.");
            }
            else
            {
                IsWorking = true;
                await Task.Delay(150);

                await Task.Run(() =>
                {
                    AdoptionModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    AnimalModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    BreedModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    CoatTypeModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    CostModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    DeathModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    DiaryModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    DonationModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    EscapeModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    FurColorModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    IncidentModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    PersonModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    MedicalRecordModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    SpeciesModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    StayModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                    WalkModel.RestoreDeleted((DateTime)Since, (DateTime)To);
                });

                ComboBoxSettings();
                IsWorking = false;
                MessageBox.Show("Záznamy od " + Since + " do " + To + " obnoveny.");
            }
        }
 public WalksViewModel(int animalID)
 {
     AnimalID = animalID;
     Walk     = new WalkModel();
     NewWalk  = new WalkModel();
 }