Пример #1
0
        public void Test_GetImage_Return_Type()
        {
            //This test checks that the PhotoController GetImage action returns a FileResult
            var context = new FakePhotoSharingContext();

            context.Photos = new[] {
                new Photo {
                    PhotoID = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                },
                new Photo {
                    PhotoID = 2, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                },
                new Photo {
                    PhotoID = 3, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                },
                new Photo {
                    PhotoID = 4, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                }
            }.AsQueryable();

            var controller = new PhotoController(context);
            var result     = controller.GetImage(1) as ActionResult;

            Assert.AreEqual(typeof(FileContentResult), result.GetType());
        }
Пример #2
0
        public void Can_Retrieve_Image_Data()
        {
            // Организация - создание объекта Photo с данными изображения
            Photo photo = new Photo
            {
                PhotoId       = 2,
                Name          = "Фото2",
                ImageData     = new byte[] { },
                ImageMimeType = "image/png"
            };

            // Организация - создание имитированного хранилища
            Mock <IPhotoRepository> mock = new Mock <IPhotoRepository>();

            mock.Setup(m => m.Photos).Returns(new List <Photo> {
                new Photo {
                    PhotoId = 1, Name = "Фото1"
                },
                photo,
                new Photo {
                    PhotoId = 3, Name = "Фото3"
                }
            }.AsQueryable());

            // Организация - создание контроллера
            PhotoController controller = new PhotoController(mock.Object);

            // Действие - вызов метода действия GetImage()
            ActionResult result = controller.GetImage(2);

            // Утверждение
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(photo.ImageMimeType, ((FileResult)result).ContentType);
        }
Пример #3
0
        public void Test_GetImage_Return_Type()
        {
            var context = new FakePhotoSharingContext {
                Photos = new[] {
                    new Photo {
                        PhotoID = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                    },
                    new Photo {
                        PhotoID = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                    },
                    new Photo {
                        PhotoID = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                    },
                    new Photo {
                        PhotoID = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                    }
                }.AsQueryable()
            };
            var controller = new PhotoController(context);
            var result     = controller.GetImage(1);

            Assert.AreEqual(
                result.GetType(),
                typeof(FileContentResult)
                );
        }
        public void Test_GetImage_Return_Type()
        {
            var controller = new PhotoController();
            var result     = controller.GetImage(1) as ActionResult;

            Assert.AreEqual(typeof(FileContentResult), result.GetType());
        }
Пример #5
0
    public void Test_GetImage_Return_Type()
    {
        //This test checks that the PhotoController GetImage action returns a FileResult
        var Photos = new[] {
            new Photo {
                PhotoID = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
            },
            new Photo {
                PhotoID = 2, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
            },
            new Photo {
                PhotoID = 3, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
            },
            new Photo {
                PhotoID = 4, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
            }
        }.AsQueryable();
        var contextMock = new Mock <IPhotoSharingContext>();

        contextMock.Setup(x => x.FindPhotoById(1)).Returns(Photos.ToArray()[0]);
        contextMock.Setup(x => x.FindPhotoById(2)).Returns(Photos.ToArray()[1]);
        contextMock.Setup(x => x.FindPhotoById(3)).Returns(Photos.ToArray()[2]);
        contextMock.Setup(x => x.FindPhotoById(4)).Returns(Photos.ToArray()[3]);
        var controller = new PhotoController(contextMock.Object);
        var result     = controller.GetImage(1) as ActionResult;

        Assert.AreEqual(typeof(FileContentResult), result.GetType());
    }
Пример #6
0
        public void Cannot_Retrieve_Image_Data_For_Invalid_ID()
        {
            // Организация - создание имитированного хранилища
            Mock <IPhotoRepository> mock = new Mock <IPhotoRepository>();

            mock.Setup(m => m.Photos).Returns(new List <Photo> {
                new Photo {
                    PhotoId = 1, Name = "Фото1"
                },
                new Photo {
                    PhotoId = 2, Name = "Фото2"
                }
            }.AsQueryable());

            // Организация - создание контроллера
            PhotoController controller = new PhotoController(mock.Object);

            // Действие - вызов метода действия GetImage()
            ActionResult result = controller.GetImage(10);

            // Утверждение
            Assert.IsNull(result);
        }
        public void Test_GetImage_ReturnType()
        {
            var fps = new FakePhotoSharingContext();

            fps.Photos = new[] {
                new Photo {
                    PhotoID = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                },
                new Photo {
                    PhotoID = 2, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                },
                new Photo {
                    PhotoID = 3, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                },
                new Photo {
                    PhotoID = 4, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                }
            }.AsQueryable();
            var controller = new PhotoController(fps);
            var photo      = controller.GetImage(2) as ActionResult;

            Assert.AreEqual(photo.GetType(), typeof(FileContentResult));
        }
        public void Test_GetImage_Return_Type()
        {
            // var controller = new PhotoController();
            var context = new FakePhotoSharingContext();

            context.Photos = new[] {
                new PhotoSharingApp.model.Photo {
                    PhotoId = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                },
                new PhotoSharingApp.model.Photo {
                    PhotoId = 2, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                },
                new PhotoSharingApp.model.Photo {
                    PhotoId = 3, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                },
                new PhotoSharingApp.model.Photo {
                    PhotoId = 4, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
                }
            }.AsQueryable();
            var controller = new PhotoController(context);
            var result     = controller.GetImage(1) as ActionResult;

            Assert.AreEqual(typeof(FileContentResult), result.GetType());
        }
Пример #9
0
    public void Test_GetImage_Null()
    {
        var Photos = new[] {
            new Photo {
                PhotoID = 1, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
            },
            new Photo {
                PhotoID = 2, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
            },
            new Photo {
                PhotoID = 3, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
            },
            new Photo {
                PhotoID = 4, PhotoFile = new byte[1], ImageMimeType = "image/jpeg"
            }
        }.AsQueryable();
        var contextMock = new Mock <IPhotoSharingContext>();

        contextMock.Setup(x => x.FindPhotoById(5)).Returns(Photos.Where(x => x.PhotoID == 5) as Photo);
        var controller = new PhotoController(contextMock.Object);
        var result     = controller.GetImage(5);

        Assert.AreEqual(null, result);
    }
Пример #10
0
    public void InitializeGameObjects(List <ItemData> itemData)
    {
        GameObject area = GameObject.Find("Area");

        foreach (Transform item in area.transform)
        {
            if (item.gameObject.name.Equals("MainGarage") || item.gameObject.name.Equals("ColliderHelper"))
            {
            }
            else
            {
                Destroy(item.gameObject);
            }
        }

        foreach (ItemData item in itemData)
        {
            if (item.ItemName.Contains("MainGarage"))
            {
                GameObject    ObjItem = GameObject.Find("MainGarage");
                RectTransform ObjRect = ObjItem.GetComponent <RectTransform>();

                ObjItem.transform.SetParent(area.transform);
                ObjItem.transform.localScale    = new Vector3(1, 1, 1);
                ObjItem.transform.localPosition = new Vector3(item.position.x, item.position.y, 1);
                ObjRect.sizeDelta = new Vector2(item.sDelta.x, item.sDelta.y);
            }
            else if (item.ItemName.Contains("ObjItem"))
            {
                string        objTextureString = Regex.Match(item.ItemName, @"\((.*?)\)").Groups[1].Value;
                GameObject    ObjItem          = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/ObjItem"));
                RectTransform ImageRect        = ObjItem.transform.Find("Image").GetComponent <RectTransform>();

                ObjItem.transform.SetParent(area.transform);
                ObjItem.transform.localScale    = new Vector3(1, 1, 1);
                ObjItem.transform.localPosition = new Vector2(item.position.x, item.position.y);

                ImageRect.sizeDelta     = new Vector3(item.sDelta.x, item.sDelta.y, 1);
                ImageRect.localScale    = new Vector3(1, 1, 1);
                ImageRect.localRotation = Quaternion.Euler(0, 0, item.position.z);

                RawImage  gObjTexture     = ObjItem.transform.Find("Image").GetComponent <RawImage>();
                var       item_search     = texturesList.Where(im => im.name == objTextureString);
                Texture2D texSearchResult = item_search.First() as Texture2D;
                gObjTexture.texture = texSearchResult;
                ObjItem.name        = "ObjItem(" + objTextureString + ")";
            }
            else if (item.ItemName.Contains("garageItem"))
            {
                GameObject    ObjItem = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/garageItem"));
                RectTransform ObjRect = ObjItem.GetComponent <RectTransform>();

                ObjItem.transform.SetParent(area.transform);
                ObjItem.transform.localScale    = new Vector3(1, 1, 1);
                ObjItem.transform.localPosition = new Vector3(item.position.x, item.position.y, 1);
                ObjRect.sizeDelta = new Vector2(item.sDelta.x, item.sDelta.y);
            }
            else if (item.ItemName.Contains("TextElem"))
            {
                GameObject ObjItem       = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/TextElem"));
                InputField ObjInputField = ObjItem.transform.Find("InputField/Text/Settings/OriginInputField").GetComponent <InputField>();
                Dropdown   ObjDrop       = ObjItem.transform.Find("InputField/Text/Settings/Dropdown").GetComponent <Dropdown>();

                ObjItem.transform.SetParent(area.transform);
                ObjItem.transform.localScale    = new Vector3(1, 1, 1);
                ObjItem.transform.localPosition = new Vector3(item.position.x, item.position.y, 1);

                ObjInputField.text = item.ItemMisc;
                ObjDrop.value      = (int)Math.Floor(item.sDelta.x);

                ObjItem.transform.Find("InputField/Text/Settings").gameObject.SetActive(false);
            }
            else if (item.ItemName.Contains("Line"))
            {
                GameObject    ObjItem = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/Line"));
                RectTransform ObjRect = ObjItem.GetComponent <RectTransform>();

                ObjItem.transform.SetParent(area.transform);
                ObjItem.transform.localScale    = new Vector3(1, 1, 1);
                ObjItem.transform.localPosition = new Vector3(item.position.x, item.position.y, 1);

                ObjRect.sizeDelta     = new Vector3(item.sDelta.x, item.sDelta.y, 1);
                ObjRect.localRotation = Quaternion.Euler(0, 0, item.position.z);

                ObjItem.transform.Find("Width/Settings").gameObject.SetActive(false);
            }
            else if (item.ItemName.Contains("Photo"))
            {
                GameObject      ObjItem         = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/Photo"));
                PhotoController photoController = ObjItem.GetComponent <PhotoController>();

                ObjItem.transform.SetParent(area.transform);
                ObjItem.transform.localScale    = new Vector3(1, 1, 1);
                ObjItem.transform.localPosition = new Vector3(item.position.x, item.position.y, 1);

                photoController.urlPhoto.text = item.ItemMisc;
                photoController.GetImage();
                ObjItem.transform.Find("Settings").gameObject.SetActive(false);
            }
        }
    }