Esempio n. 1
0
        public void PostingABodyReturnsAValidAbsoluteURL()
        {
            //Arrange
            var key = "abcdef1234";
            var testData = "Test data";
            var serviceName = "service name";

            var mockService = new MockService(key, serviceName, testData);

            var responseRepository = new Mock<IMockServiceStore>();

            var controller = new DummyController(responseRepository.Object)
            {
                Request = request
            };

            responseRepository.Setup(x => x.CreateAsync(mockService));

            dynamic service = new object();
            service.name = "Unit test name";

            //Act
            var returnedString = controller.Post(service);

            //Assert
            var url = new Uri(returnedString.ToString());

            Assert.IsTrue(url.IsAbsoluteUri);
        }
Esempio n. 2
0
        public async Task UpdateAsync(MockService mockResponse)
        {
            var service = await FindbyKey(mockResponse.Key);

            service["body"] = mockResponse.Body;
            await service.SaveAsync();
        }
Esempio n. 3
0
 public Task CreateAsync(MockService mockResponse)
 {
     var dbMockResponse = new ParseObject("MockService");
     dbMockResponse["key"] = mockResponse.Key;
     dbMockResponse["body"] = mockResponse.Body;
     dbMockResponse["name"] = mockResponse.Name;
     return dbMockResponse.SaveAsync();
 }
Esempio n. 4
0
        public static MockService FromParseObject(ParseObject @object)
        {
            var service = new MockService();

            service.Key = @object["key"].ToString();
            service.Body = @object["body"].ToString();

            return service;
        }
Esempio n. 5
0
        public async System.Threading.Tasks.Task<object> Post(MockService mockService)
        {
            mockService.Key = RandomStringGenerator.AlphaNumericString(10);

            var createServiceTask = mockServiceStore.CreateAsync(mockService);

            var uriString = Url.Link("DefaultApi", new { controller = "Dummy", id = mockService.Key });
            var editUrl = Url.Link("EditApi", new { controller = "Edit", id = mockService.Key });

            var uri = new Uri(uriString);

            await createServiceTask;

            return new { url = uri.AbsoluteUri, key = mockService.Key, editUrl = editUrl, name = mockService.Name };
        }
Esempio n. 6
0
        public async Task PostReturnsUrlContainingResponseKey()
        {
            //Arrange
            var key = "abcdef1234";
            var testData = "Test data";

            var mockResponseRepository = new Mock<IMockServiceStore>();

            var mockService = new MockService("key", "name", "body");

            var controller = new DummyController(mockResponseRepository.Object)
            {
                Request = request
            };

            mockResponseRepository.Setup(r => r.CreateAsync(mockService));

            //Act
            var returnedString = await controller.Post(mockService);

            //Assert
            StringAssert.Contains(key, returnedString.ToString());
        }
Esempio n. 7
0
        // PUT api/<controller>/5
        public async Task Put(string id)
        {
            var body = await Request.Content.ReadAsStringAsync();

            var mockService = new MockService(id, "", body);

            await mockServiceStore.UpdateAsync(mockService);
        }