Пример #1
0
        public void ShouldThrowWhenUpdatingTooMuchQuantity()
        {
            ShoppingCartRecord item = _repo.Find(0, 32);

            item.Quantity    = 100;
            item.DateCreated = DateTime.Now;
            InvalidQuantityException ex = Assert.Throws <InvalidQuantityException>(() => _repo.Update(item));

            Assert.Equal("Can't add more product than available in stock", ex.Message);
        }
Пример #2
0
        public static void InvalidQuantityException_ctor_string()
        {
            // Arrange
            const string expectedMessage = "message";

            // Act
            InvalidQuantityException sut = new InvalidQuantityException(expectedMessage);

            // Assert
            Assert.Null(sut.ResourceReferenceProperty);
            Assert.Null(sut.InnerException);
            Assert.Equal(expectedMessage, sut.Message);
        }
Пример #3
0
        public static void InvalidQuantityException_default_ctor()
        {
            // Arrange
            const string expectedMessage = "Exception of type 'SpyStore.DAL.Exceptions.InvalidQuantityException' was thrown.";

            // Act
            InvalidQuantityException sut = new InvalidQuantityException();

            // Assert
            Assert.Null(sut.ResourceReferenceProperty);
            Assert.Null(sut.InnerException);
            Assert.Equal(expectedMessage, sut.Message);
        }
Пример #4
0
        public void ShouldThrowWhenAddingToMuchQuantity()
        {
            _repo.Context.SaveChanges();
            ShoppingCartRecord item = new ShoppingCartRecord
            {
                ProductId   = 2,
                Quantity    = 500,
                DateCreated = DateTime.Now,
                CustomerId  = 2
            };
            InvalidQuantityException ex = Assert.Throws <InvalidQuantityException>(() => _repo.Update(item));

            Assert.Equal("Can't add more product than available in stock", ex.Message);
        }
Пример #5
0
        public static void InvalidQuantityException_serialization_deserialization_test()
        {
            // Arrange
            Exception innerEx = new Exception("foo");
            InvalidQuantityException originalException = new InvalidQuantityException("message", innerEx)
            {
                ResourceReferenceProperty = "MyReferenceProperty"
            };

            byte[]          buffer    = new byte[4096];
            MemoryStream    ms        = new MemoryStream(buffer);
            MemoryStream    ms2       = new MemoryStream(buffer);
            BinaryFormatter formatter = new BinaryFormatter();

            // Act
            formatter.Serialize(ms, originalException);
            InvalidQuantityException deserializedException = (InvalidQuantityException)formatter.Deserialize(ms2);

            // Assert
            Assert.Equal(originalException.ResourceReferenceProperty, deserializedException.ResourceReferenceProperty);
            Assert.Equal(originalException.InnerException.Message, deserializedException.InnerException.Message);
            Assert.Equal(originalException.Message, deserializedException.Message);
        }