Exemplo n.º 1
0
 void Start()
 {
     //particles = particles.GetComponent<ParticleSystem> ();
     offCenter  = new Vector3(-0.44f, 0.34f, this.transform.position.z);
     starCount  = starCount.GetComponent <StarsController> ();
     starPickup = GetComponent <AudioSource> ();
 }
        public StarsHttpClientV1Test()
        {
            _persistence = new StarsMemoryPersistence();
            _controller  = new StarsController();
            _client      = new StarsHttpClientV1();
            _service     = new StarsHttpServiceV1();

            IReferences references = References.FromTuples(
                new Descriptor("stars", "persistence", "memory", "default", "1.0"), _persistence,
                new Descriptor("stars", "controller", "default", "default", "1.0"), _controller,
                new Descriptor("stars", "client", "http", "default", "1.0"), _client,
                new Descriptor("stars", "service", "http", "default", "1.0"), _service
                );

            _controller.SetReferences(references);

            _service.Configure(HttpConfig);
            _service.SetReferences(references);

            _client.Configure(HttpConfig);
            _client.SetReferences(references);

            _fixture = new StarsClientV1Fixture(_client);

            _service.OpenAsync(null).Wait();
            _client.OpenAsync(null).Wait();
        }
        public void DeletePost_WithSuccessfullDelete_ShouldReturnRedirectResult()
        {
            // Arranges
            Mock <IStarService> starService = new Mock <IStarService>();

            starService
            .Setup(s => s.Delete(It.IsAny <int>()))
            .Returns(true);

            Mock <ITempDataDictionary> tempData = new Mock <ITempDataDictionary>();

            string successmessage = null;

            tempData
            .SetupSet(t => t[WebConstants.TempDataSuccessMessage]    = It.IsAny <string>())
            .Callback((string key, object message) => successmessage = message as string);

            StarsController starsController = new StarsController(starService.Object, null);

            starsController.TempData = tempData.Object;

            const int discoveryId = 1;

            // Act
            IActionResult result = starsController.DeletePost(1, discoveryId);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);
            RedirectToActionResult redirectResult = result as RedirectToActionResult;

            this.AssertRedirect(discoveryId, redirectResult);
            Assert.Equal(string.Format(WebConstants.SuccessfullEntityOperation, Star, WebConstants.Deleted), successmessage);
        }
        public void CreatePost_WithExistingStarName_ShouldReturnView()
        {
            // Arrange
            Mock <IStarService> starService = new Mock <IStarService>();

            starService
            .Setup(s => s.Exists(It.IsAny <string>()))
            .Returns(true);

            Mock <ITempDataDictionary> tempData = new Mock <ITempDataDictionary>();

            string errorMessage = null;

            tempData
            .SetupSet(t => t[WebConstants.TempDataErrorMessage]    = It.IsAny <string>())
            .Callback((string key, object message) => errorMessage = message as string);

            StarFormServiceModel formModel       = this.GetStarFormModel();
            StarsController      starsController = new StarsController(starService.Object, null);

            starsController.TempData = tempData.Object;

            // Act
            IActionResult result = starsController.Create(1, formModel);

            // Assert
            Assert.IsType <ViewResult>(result);
            object model = (result as ViewResult).Model;

            Assert.IsType <StarFormServiceModel>(model);
            StarFormServiceModel returnModel = model as StarFormServiceModel;

            this.AssertStars(formModel, returnModel);
            Assert.Equal(string.Format(WebConstants.EntryExists, Star), errorMessage);
        }
        public void CreatePost_WithNotSuccessfullyCreatedStar_ShouldReturnBadRequest()
        {
            // Arrange
            Mock <IStarService>      starService      = new Mock <IStarService>();
            Mock <IDiscoveryService> discoveryService = new Mock <IDiscoveryService>();

            starService
            .Setup(s => s.Exists(It.IsAny <string>()))
            .Returns(false);

            discoveryService
            .Setup(d => d.TotalStars(It.IsAny <int>()))
            .Returns(1);

            starService
            .Setup(s => s.Create(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>()))
            .Returns(false);

            StarsController starsController = new StarsController(starService.Object, discoveryService.Object);

            starsController.TempData = Mock.Of <ITempDataDictionary>();
            StarFormServiceModel formModel = this.GetStarFormModel();

            // Act
            IActionResult result = starsController.Create(1, formModel);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
        public void EditPost_WithNotSuccessfullEdit_ShouldReturnView()
        {
            // Arranges
            Mock <IStarService> starService = new Mock <IStarService>();

            StarFormServiceModel model = this.GetStarFormModel();

            starService
            .Setup(s => s.Exists(It.IsAny <string>()))
            .Returns(false);

            starService
            .Setup(s => s.GetName(It.IsAny <int>()))
            .Returns(model.Name);

            starService
            .Setup(s => s.Edit(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>()))
            .Returns(false);

            StarsController starsController = new StarsController(starService.Object, null);

            // Act
            IActionResult result = starsController.Edit(1, 1, model);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
Exemplo n.º 7
0
        public async Task SetUp()
        {
            StarsTracker = new DummyStarsTracker();
            await StarsTracker.SetToRandom();

            Controller = new StarsController(StarsTracker);
            Controller.ControllerContext.HttpContext = new DefaultHttpContext();
        }
        public void CreateGet_ShouldReturnView()
        {
            // Arrange
            StarsController starsController = new StarsController(null, null);

            // Act
            IActionResult result = starsController.Create();

            // Assert
            Assert.IsType <ViewResult>(result);
        }
        public void DeletePost_WithNotSuccessfullDelete_ShouldReturnBadRequest()
        {
            // Arranges
            Mock <IStarService> starService = new Mock <IStarService>();

            starService
            .Setup(s => s.Delete(It.IsAny <int>()))
            .Returns(false);

            StarsController starsController = new StarsController(starService.Object, null);

            // Act
            IActionResult result = starsController.DeletePost(1, 1);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
Exemplo n.º 10
0
        public void EditGet_WithNotExistingId_ShouldReturnBadRequest()
        {
            // Arrange
            Mock <IStarService>  starService = new Mock <IStarService>();
            StarFormServiceModel model       = null;

            starService
            .Setup(s => s.GetForm(It.IsAny <int>()))
            .Returns(model);

            StarsController starsController = new StarsController(starService.Object, null);

            // Act
            IActionResult result = starsController.Edit(1, 1);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
Exemplo n.º 11
0
        public void CreatePost_WithSuccessfullyCreatedStar_ShouldReturnRedirectResult()
        {
            // Arrange
            Mock <IStarService>      starService      = new Mock <IStarService>();
            Mock <IDiscoveryService> discoveryService = new Mock <IDiscoveryService>();

            const int discoveryId = 1;

            starService
            .Setup(s => s.Exists(It.IsAny <string>()))
            .Returns(false);

            discoveryService
            .Setup(d => d.TotalStars(It.IsAny <int>()))
            .Returns(1);

            starService
            .Setup(s => s.Create(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>()))
            .Returns(true);

            Mock <ITempDataDictionary> tempData = new Mock <ITempDataDictionary>();

            string successmessage = null;

            tempData
            .SetupSet(t => t[WebConstants.TempDataSuccessMessage]    = It.IsAny <string>())
            .Callback((string key, object message) => successmessage = message as string);

            StarFormServiceModel formModel       = this.GetStarFormModel();
            StarsController      starsController = new StarsController(starService.Object, discoveryService.Object);

            starsController.TempData = tempData.Object;

            // Act
            IActionResult result = starsController.Create(discoveryId, formModel);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);
            RedirectToActionResult redirectResult = result as RedirectToActionResult;

            this.AssertRedirect(discoveryId, redirectResult);
            Assert.Equal(string.Format(WebConstants.SuccessfullEntityOperation, Star, WebConstants.Added), successmessage);
        }
Exemplo n.º 12
0
        public void CreatePost_WithDiscoveryWithMoreThanThreeStars_ShouldReturnView()
        {
            // Arrange
            Mock <IStarService>      starService      = new Mock <IStarService>();
            Mock <IDiscoveryService> discoveryService = new Mock <IDiscoveryService>();

            starService
            .Setup(s => s.Exists(It.IsAny <string>()))
            .Returns(false);

            discoveryService
            .Setup(d => d.TotalStars(It.IsAny <int>()))
            .Returns(3);

            Mock <ITempDataDictionary> tempData = new Mock <ITempDataDictionary>();

            string errorMessage = null;

            tempData
            .SetupSet(t => t[WebConstants.TempDataErrorMessage]    = It.IsAny <string>())
            .Callback((string key, object message) => errorMessage = message as string);

            StarFormServiceModel formModel       = this.GetStarFormModel();
            StarsController      starsController = new StarsController(starService.Object, discoveryService.Object);

            starsController.TempData = tempData.Object;

            // Act
            IActionResult result = starsController.Create(1, formModel);

            // Assert
            Assert.IsType <ViewResult>(result);
            object model = (result as ViewResult).Model;

            Assert.IsType <StarFormServiceModel>(model);
            StarFormServiceModel returnModel = model as StarFormServiceModel;

            this.AssertStars(formModel, returnModel);
            Assert.Equal(string.Format(
                             DataConstants.DiscoveryConstants.MaxStarsPerDiscoveryErrorMessage,
                             DataConstants.DiscoveryConstants.MaxStarsPerDiscovery),
                         errorMessage);
        }
Exemplo n.º 13
0
        public StarsHttpServiceV1Test()
        {
            _persistence = new StarsMemoryPersistence();
            _controller  = new StarsController();
            _service     = new StarsHttpServiceV1();

            IReferences references = References.FromTuples(
                new Descriptor("stars", "persistence", "memory", "default", "1.0"), _persistence,
                new Descriptor("stars", "controller", "default", "default", "1.0"), _controller,
                new Descriptor("stars", "service", "http", "default", "1.0"), _service
                );

            _controller.SetReferences(references);

            _service.Configure(HttpConfig);
            _service.SetReferences(references);

            //_service.OpenAsync(null).Wait();
            // Todo: This is defect! Open shall not block the tread
            Task.Run(() => _service.OpenAsync(null));
            Thread.Sleep(1000); // Just let service a sec to be initialized
        }
Exemplo n.º 14
0
        public void EditGet_WithExistingId_ShouldReturnView()
        {
            // Arrange
            Mock <IStarService>  starService = new Mock <IStarService>();
            StarFormServiceModel formModel   = this.GetStarFormModel();

            starService
            .Setup(s => s.GetForm(It.IsAny <int>()))
            .Returns(formModel);

            StarsController starsController = new StarsController(starService.Object, null);

            // Act
            IActionResult result = starsController.Edit(1, 1);

            // Assert
            Assert.IsType <ViewResult>(result);
            object model = (result as ViewResult).Model;

            Assert.IsType <StarFormServiceModel>(model);
            StarFormServiceModel returnModel = model as StarFormServiceModel;

            this.AssertStars(formModel, returnModel);
        }
 public void Setup()
 {
     _controller = new StarsController();
     _builder    = new TestControllerBuilder();
     _builder.InitializeController(_controller);
 }