public async Task Create_plant_details_success()
        {
            //Arrange
            var plantDetailsContext = new PlantListingContext(_dbOptions);

            var userId = "cktan";
            var validCreatePlantDetailsViewModel = new CreateEditPlantDetailsViewModel()
            {
                Name        = "Bean sprouts",
                Description = "Organic bean sprouts",
                Category    = "Vegetable",
                Price       = 0.80m,
                Weight      = 100.0m,
                Unit        = "g",
                Stock       = 100,
                UserId      = userId
            };

            var expectedPlantDetailsId = 9;
            var expectedName           = "Bean sprouts";
            var expectedDescription    = "Organic bean sprouts";
            var expectedCategory       = "Vegetable";
            var expectedPrice          = 0.80m;
            var expectedWeight         = 100.0m;
            var expectedUnit           = "g";
            var expectedStock          = 100;
            var expectedUserId         = "cktan";

            //Act
            var plantDetailsController = new PlantListingController(plantDetailsContext, _mockPlantImageService.Object);
            var actionResult           = await plantDetailsController.CreatePlantDetails(validCreatePlantDetailsViewModel);

            //Assert
            Assert.IsType <CreatedAtActionResult>(actionResult.Result);
            Assert.Equal("GetPlantDetails", (actionResult.Result as CreatedAtActionResult).ActionName);
            Assert.IsType <PlantDetailsViewModel>((actionResult.Result as CreatedAtActionResult).Value);

            PlantDetailsViewModel actualViewModel = (actionResult.Result as CreatedAtActionResult).Value as PlantDetailsViewModel;

            Assert.Equal(expectedPlantDetailsId, actualViewModel.PlantDetailsId);
            Assert.Equal(expectedName, actualViewModel.Name);
            Assert.Equal(expectedDescription, actualViewModel.Description);
            Assert.Equal(expectedCategory, actualViewModel.Category);
            Assert.Equal(expectedPrice, actualViewModel.Price);
            Assert.Equal(expectedWeight, actualViewModel.Weight);
            Assert.Equal(expectedUnit, actualViewModel.Unit);
            Assert.Equal(expectedStock, actualViewModel.Stock);
            Assert.Equal(expectedUserId, actualViewModel.UserId);
        }
Exemplo n.º 2
0
        public PlantDetailsPage(Plant plant)
        {
            InitializeComponent();

            this.BindingContext = new PlantDetailsViewModel(plant, this);
            vm = this.BindingContext as PlantDetailsViewModel;

            MessagingCenter.Subscribe <object>(this as object, "PhotoAdded", _ =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    this.PhotoCollectionView.ScrollTo(0);
                });
            });
        }
Exemplo n.º 3
0
        public IActionResult Details(int plantId)
        {
            PlantDetailsViewModel plant = PlantDetailsViewModel.GetPlant(plantId, context);

            return(View(plant));
        }