コード例 #1
0
 public void Start_DoItTwice_ThrowsApplicationException()
 {
     // Arrange
     using (var fisrtServer = new VocabularyServer(VocabularyRequestHandlerStabFactory.Stub(), Url))
     {
         var start = fisrtServer.StartAsync();
         using (var secondServer = new VocabularyServer(VocabularyRequestHandlerStabFactory.Stub(), Url))
         {
             // Assert
             var ex = Assert.Throws <AggregateException>(() => secondServer.StartAsync().Wait());
             Assert.IsInstanceOf <ApplicationException>(ex.InnerException);
             Assert.IsInstanceOf <HttpListenerException>(ex.InnerException.InnerException);
         }
         fisrtServer.Stop();
     }
 }
コード例 #2
0
        public async Task ProcessRequest_HandlerThorwsException_ReceiveInternalServerError()
        {
            // Arrange
            using (var server = new VocabularyServer(VocabularyRequestHandlerStabFactory.ExceptionHandle(), Url))
            {
                var start = server.StartAsync();
                using (var request = new VocabularyRequest(new Uri(Url), "add"))
                {
                    // Act
                    var responce = await request.PostAsync();

                    // Assert
                    Assert.AreEqual(responce, string.Format(Resources.Default.ResponseErrorCode, "InternalServerError"));
                }

                server.Stop();
            }
        }
コード例 #3
0
        public async Task ProcessRequest_HandlerReturnResult_ReceiveThatResult()
        {
            // Arrange
            var command = "aaa";
            var result  = "bbb";

            using (var server = new VocabularyServer(
                       VocabularyRequestHandlerStabFactory.Handle(command, result), Url))
            {
                var start = server.StartAsync();
                using (var request = new VocabularyRequest(new Uri(Url), command))
                {
                    // Act
                    var responce = await request.PostAsync();

                    // Assert
                    Assert.AreEqual(responce, result);
                }

                server.Stop();
            }
        }