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);
        }
        public async Task UpdateAsync(MockService mockResponse)
        {
            var service = await FindbyKey(mockResponse.Key);

            service["body"] = mockResponse.Body;
            await service.SaveAsync();
        }
 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();
 }
Beispiel #4
0
        public static MockService FromParseObject(ParseObject @object)
        {
            var service = new MockService();

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

            return service;
        }
Beispiel #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 };
        }
        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());
        }
Beispiel #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);
        }