<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nguyễn Tiến Dũng</title>
    <description>The latest articles on DEV Community by Nguyễn Tiến Dũng (@mossi4476).</description>
    <link>https://dev.to/mossi4476</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F743033%2F1970aa77-5206-4e6e-b013-3eac4405c6fb.png</url>
      <title>DEV Community: Nguyễn Tiến Dũng</title>
      <link>https://dev.to/mossi4476</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mossi4476"/>
    <language>en</language>
    <item>
      <title>End to end testing concept</title>
      <dc:creator>Nguyễn Tiến Dũng</dc:creator>
      <pubDate>Sun, 04 Jun 2023 23:23:16 +0000</pubDate>
      <link>https://dev.to/mossi4476/end-to-end-testing-concept-9oa</link>
      <guid>https://dev.to/mossi4476/end-to-end-testing-concept-9oa</guid>
      <description>&lt;p&gt;End-to-end test là loại test toàn diện nhất, nó kiểm tra hệ thống từ đầu đến cuối, bao gồm tất cả các thành phần liên quan.&lt;/p&gt;

&lt;p&gt;Nó có các đặc điểm chính sau:&lt;/p&gt;

&lt;p&gt;Kiểm tra toàn bộ quy trình hoạt động của hệ thống từ đầu đến cuối. Từ giao diện người dùng đến cơ sở dữ liệu.&lt;/p&gt;

&lt;p&gt;Sử dụng các trình duyệt hoặc ứng dụng thực sự để thực hiện các bước trong quy trình.&lt;/p&gt;

&lt;p&gt;Đòi hỏi phải khởi chạy toàn bộ môi trường hệ thống như ứng dụng, API, cơ sở dữ liệu.&lt;/p&gt;

&lt;p&gt;Có thể phát hiện các vấn đề liên quan đến tích hợp giữa các thành phần khác nhau.&lt;/p&gt;

&lt;p&gt;Ví dụ:&lt;/p&gt;

&lt;p&gt;Người dùng truy cập vào trang web thông qua trình duyệt, tương tác với giao diện người dùng&lt;/p&gt;

&lt;p&gt;Trang web gọi API và API gọi cơ sở dữ liệu&lt;/p&gt;

&lt;p&gt;Kiểm tra liệu kết quả trả về có đúng với kỳ vọng hay không.&lt;/p&gt;

&lt;p&gt;Như vậy, end-to-end test bao gồm toàn bộ quá trình tương tác của người dùng cuối với hệ thống, giúp đảm bảo tính toàn diện và tích hợp chính xác giữa các thành phần. Tuy nhiên, nó cũng tốn nhiều thời gian để thực hiện so với các loại test khác.&lt;/p&gt;

&lt;p&gt;End-to-end test thường được thực hiện cuối cùng để kiểm tra toàn bộ hệ thống hoạt động như mong đợi.&lt;/p&gt;

</description>
      <category>testing</category>
    </item>
    <item>
      <title>Test Driven Development Concept</title>
      <dc:creator>Nguyễn Tiến Dũng</dc:creator>
      <pubDate>Sun, 04 Jun 2023 23:20:28 +0000</pubDate>
      <link>https://dev.to/mossi4476/test-driven-development-concept-fn0</link>
      <guid>https://dev.to/mossi4476/test-driven-development-concept-fn0</guid>
      <description>&lt;p&gt;1.Viết test case trước (test-first): Đặt ra các giả thuyết cho chức năng cần hoàn thành và viết các test case dựa trên đó.&lt;/p&gt;

&lt;p&gt;2.Chạy test case: Chạy các test case và chúng sẽ fail do chưa có code thực hiện.&lt;/p&gt;

&lt;p&gt;3.Viết code để làm test case pass: Viết code càng đơn giản nhất để làm test case pass, sau đó chạy lại test để đảm bảo đúng yêu cầu.&lt;/p&gt;

&lt;p&gt;4.Refactor code nếu cần: Sửa code để tối ưu hóa, rồi chạy lại test case đảm bảo vẫn đúng.&lt;/p&gt;

&lt;p&gt;Qua đó TDD giúp có bộ khung test chi tiết trước khi viết code, đảm bảo chất lượng và tính bền vững cho phần mềm.&lt;/p&gt;

&lt;p&gt;Vậy là TDD là phương pháp phát triển phần mềm bằng cách viết test case trước rồi mới viết code thực hiện, quá trình lặp đi lặp lại để tối ưu hóa code.&lt;/p&gt;

&lt;p&gt;Ví dụ:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Calculator
{
    public int Add(int x, int y) { ... }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test-First:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[TestClass]
public class CalculatorTests 
{
    [TestMethod]
    public void Add_TwoPositiveNumbers_ReturnsCorrectSum()
    {
        // Arrange
        var calculator = new Calculator();

        // Act
        var result = calculator.Add(2, 3);  

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

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Còn nếu code fail thì sẽ không thực hiện đoạn Add()&lt;br&gt;
Chạy Test-Case nếu chúng pass sẽ thực hiện đoạn Add()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public int Add(int x, int y) 
{
    return x + y;  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Refactor code nếu code vẫn chạy pass:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public int Add(int x, int y)
{
    return CalculateSum(x, y);
}

rivate int CalculateSum(int x, int y)
{
    return x + y;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mình có thể viết nhiều đoạn code hơn cho đoạn test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[TestMethod]
public void Add_TwoNegativeNumbers_ReturnsCorrectSum() { ... }

[TestMethod]
public void Add_OneNegativeOnePositive_ReturnsCorrectSum() { ... }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>testing</category>
    </item>
    <item>
      <title>Integration testing concept</title>
      <dc:creator>Nguyễn Tiến Dũng</dc:creator>
      <pubDate>Sun, 04 Jun 2023 23:15:01 +0000</pubDate>
      <link>https://dev.to/mossi4476/integration-testing-trong-net-1fne</link>
      <guid>https://dev.to/mossi4476/integration-testing-trong-net-1fne</guid>
      <description>&lt;p&gt;Integration testing là một loại test nhằm đảm bảo rằng các thành phần, module của phần mềm hoạt động đúng cách khi được tích hợp với nhau.&lt;/p&gt;

&lt;p&gt;Trong khi unit test tập trung vào từng đơn vị code riêng lẻ, integration test tập trung vào việc tích hợp nhiều đơn vị lại với nhau.&lt;/p&gt;

&lt;p&gt;Cụ thể:&lt;/p&gt;

&lt;p&gt;Integration test kiểm tra sự tương tác giữa các module/component khác nhau.&lt;/p&gt;

&lt;p&gt;Nó liên quan đến tích hợp các phần phần mềm với nhau, ví dụ API với ứng dụng, ứng dụng với cơ sở dữ liệu,...&lt;/p&gt;

&lt;p&gt;Việc integration test được thực hiện sau khi unit test các thành phần riêng lẻ.&lt;/p&gt;

&lt;p&gt;Nó giúp phát hiện các vấn đề tương tác giữa các thành phần khi được tích hợp với nhau.&lt;/p&gt;

&lt;p&gt;Test việc tích hợp API với ứng dụng để kiểm tra liệu ứng dụng có gọi đúng API và xử lý dữ liệu từ API một cách chính xác.&lt;/p&gt;

&lt;p&gt;Test ứng dụng với cơ sở dữ liệu để đảm bảo việc truy vấn, cập nhật dữ liệu được thực hiện đúng.&lt;/p&gt;

&lt;p&gt;Nói tóm lại, integration test là kiểm tra sự tương tác giữa các thành phần đã được unit test để đảm bảo chúng hoạt động đúng khi tích hợp với nhau.&lt;/p&gt;

&lt;p&gt;Ví dụ:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[TestClass]
public class ApiIntegrationTest 
{
    [TestMethod]   
    public void GetData_CheckResult()
    {
        // Gọi API
        var apiResult = Api.GetData();

        // Gọi ứng dụng xử lý dữ liệu từ API         
        var result = App.ProcessData(apiResult);  

        // Kiểm tra kết quả
        Assert.AreEqual(expectedResult, result);    
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ở đây tương tự:&lt;/p&gt;

&lt;p&gt;Chúng ta gọi API bằng Api.GetData()&lt;/p&gt;

&lt;p&gt;Gọi ứng dụng xử lý dữ liệu từ API bằng App.ProcessData(apiResult)&lt;/p&gt;

&lt;p&gt;Cuối cùng assert kết quả trả về với kết quả mong đợi.&lt;/p&gt;

&lt;p&gt;Đây là một đoạn integration test đơn giản để kiểm tra sự tương tác giữa API và ứng dụng bằng C# .NET.&lt;/p&gt;

&lt;p&gt;Những điểm chính khi viết integration test:&lt;/p&gt;

&lt;p&gt;Khởi tạo dữ liệu mock nếu cần để test&lt;/p&gt;

&lt;p&gt;Gọi các component cần test tương tác với nhau&lt;/p&gt;

&lt;p&gt;Kiểm tra kết quả trả về&lt;/p&gt;

&lt;p&gt;Ưu tiên dùng database in-memory để test nhanh hơn.&lt;/p&gt;

&lt;p&gt;Các loại test này rất quan trọng để đảm bảo mọi thứ hoạt động đúng đắn khi được tích hợp.&lt;/p&gt;

</description>
      <category>testing</category>
    </item>
    <item>
      <title>Unit testing concept</title>
      <dc:creator>Nguyễn Tiến Dũng</dc:creator>
      <pubDate>Sun, 04 Jun 2023 23:07:48 +0000</pubDate>
      <link>https://dev.to/mossi4476/unit-testing-cho-net-5gig</link>
      <guid>https://dev.to/mossi4476/unit-testing-cho-net-5gig</guid>
      <description>&lt;p&gt;Unit test là một loại test cụ thể được sử dụng trong TDD.&lt;/p&gt;

&lt;p&gt;Unit test là test mỗi đơn vị/module riêng biệt của code như một class, function hoặc method.&lt;/p&gt;

&lt;p&gt;Nó được dùng để:&lt;/p&gt;

&lt;p&gt;Kiểm tra hàm/phương thức đó hoạt động đúng như mong đợi.&lt;/p&gt;

&lt;p&gt;Tìm ra các lỗi ngay từ ban đầu trong quá trình phát triển code.&lt;/p&gt;

&lt;p&gt;Giúp bảo trì và mở rộng code dễ dàng hơn bằng cách chạy các unit test khi có sự thay đổi xảy ra.&lt;/p&gt;

&lt;p&gt;Ví dụ đoạn code dưới đây:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            // Arrange
            var calculator = new Calculator();

            // Act
            var result = calculator.Add(2, 3); 

            // Assert 
            Assert.AreEqual(5, result);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Giải thích:&lt;/p&gt;

&lt;p&gt;TestClass: Đánh dấu lớp chứa các unit test.&lt;/p&gt;

&lt;p&gt;TestMethod: Đánh dấu phương thức là một unit test.&lt;/p&gt;

&lt;p&gt;Arrange: Chuẩn bị dữ liệu cần thiết.&lt;/p&gt;

&lt;p&gt;Act: Thực hiện hành động cần test.&lt;/p&gt;

&lt;p&gt;Assert: Kiểm tra kết quả có đúng như mong đợi hay không.&lt;/p&gt;

</description>
      <category>testing</category>
    </item>
    <item>
      <title>MVVM In C# .NET</title>
      <dc:creator>Nguyễn Tiến Dũng</dc:creator>
      <pubDate>Tue, 11 Apr 2023 09:30:42 +0000</pubDate>
      <link>https://dev.to/mossi4476/mvvm-in-c-net-24a6</link>
      <guid>https://dev.to/mossi4476/mvvm-in-c-net-24a6</guid>
      <description>&lt;p&gt;MVVM (Model-View-ViewModel) is a design pattern used in the development of user interfaces, particularly in the context of WPF (Windows Presentation Foundation) and Silverlight applications in C# .NET. It helps separate concerns between the user interface (View), the data (Model), and the application logic (ViewModel).&lt;/p&gt;

&lt;p&gt;Here's a brief overview of the MVVM components:&lt;/p&gt;

&lt;p&gt;Model: This represents the data and business logic of the application. It provides data to the ViewModel.&lt;/p&gt;

&lt;p&gt;View: This represents the user interface (UI) of the application. It binds to the ViewModel to display data and to trigger events.&lt;/p&gt;

&lt;p&gt;ViewModel: This acts as a mediator between the View and the Model. It provides data to the View by interacting with the Model and exposes methods and commands for the View to interact with the Model.&lt;/p&gt;

&lt;p&gt;Here are some key concepts to understand in MVVM:&lt;/p&gt;

&lt;p&gt;Data Binding: This is the mechanism by which data is automatically synchronized between the View and the ViewModel. It is accomplished using data binding expressions in XAML.&lt;/p&gt;

&lt;p&gt;Commands: Commands allow the View to trigger actions in the ViewModel, without requiring knowledge of how the ViewModel performs those actions.&lt;/p&gt;

&lt;p&gt;Dependency Injection: This is a technique used to inject dependencies (such as data services) into the ViewModel, allowing it to be more modular and testable.&lt;/p&gt;

&lt;p&gt;Unit Testing: By separating the concerns of the application, MVVM makes it easier to write unit tests for the ViewModel and Model components.&lt;/p&gt;

&lt;p&gt;Overall, MVVM is a powerful pattern that helps make C# .NET applications more modular, testable, and maintainable.&lt;/p&gt;

&lt;p&gt;Model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class CustomerModel
{
    public string Name { get; set; }
    public string Address { get; set; }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ViewModel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class CustomerViewModel : INotifyPropertyChanged
{
    private CustomerModel _customer;

    public CustomerViewModel()
    {
        _customer = new CustomerModel();
    }

    public string Name
    {
        get { return _customer.Name; }
        set
        {
            _customer.Name = value;
            OnPropertyChanged(nameof(Name));
        }
    }

    public string Address
    {
        get { return _customer.Address; }
        set
        {
            _customer.Address = value;
            OnPropertyChanged(nameof(Address));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected void OnPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;View (XAML):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Window x:Class="MyApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="clr-namespace:MyApp.ViewModels"
        Title="MainWindow" Height="450" Width="800"&amp;gt;
    &amp;lt;Window.DataContext&amp;gt;
        &amp;lt;vm:CustomerViewModel /&amp;gt;
    &amp;lt;/Window.DataContext&amp;gt;
    &amp;lt;Grid&amp;gt;
        &amp;lt;Grid.RowDefinitions&amp;gt;
            &amp;lt;RowDefinition Height="Auto" /&amp;gt;
            &amp;lt;RowDefinition Height="Auto" /&amp;gt;
            &amp;lt;RowDefinition Height="Auto" /&amp;gt;
        &amp;lt;/Grid.RowDefinitions&amp;gt;
        &amp;lt;Grid.ColumnDefinitions&amp;gt;
            &amp;lt;ColumnDefinition Width="Auto" /&amp;gt;
            &amp;lt;ColumnDefinition Width="*" /&amp;gt;
        &amp;lt;/Grid.ColumnDefinitions&amp;gt;
        &amp;lt;Label Grid.Row="0" Grid.Column="0" Content="Name:" /&amp;gt;
        &amp;lt;TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Name}" /&amp;gt;
        &amp;lt;Label Grid.Row="1" Grid.Column="0" Content="Address:" /&amp;gt;
        &amp;lt;TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Address}" /&amp;gt;
        &amp;lt;Button Grid.Row="2" Grid.Column="1" Content="Save" Command="{Binding SaveCommand}" /&amp;gt;
    &amp;lt;/Grid&amp;gt;
&amp;lt;/Window&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the CustomerModel class represents the data, the CustomerViewModel class represents the logic, and the XAML View represents the UI. The DataContext property of the Window is set to an instance of the CustomerViewModel class, which provides the data and behavior for the View. Data binding expressions are used to synchronize data between the ViewModel and the View, and the SaveCommand property on the ViewModel exposes a command that the View can use to trigger an action.&lt;/p&gt;

</description>
      <category>aspdotnet</category>
      <category>webdev</category>
    </item>
    <item>
      <title>MVC Architecture in .NET App</title>
      <dc:creator>Nguyễn Tiến Dũng</dc:creator>
      <pubDate>Mon, 27 Mar 2023 04:33:23 +0000</pubDate>
      <link>https://dev.to/mossi4476/mvc-architecture-in-net-app-4m94</link>
      <guid>https://dev.to/mossi4476/mvc-architecture-in-net-app-4m94</guid>
      <description>&lt;p&gt;Hey Hello, In this article series I’m going to cover the following areas in the Web development with C#, ASP .NET Core MVC, MVVM Tech Stack.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;ASP .NET Core&lt;/li&gt;
&lt;li&gt;Razor Pages and Blazor&lt;/li&gt;
&lt;li&gt;MVC Architecture&lt;/li&gt;
&lt;li&gt;MVVM Architecture&lt;/li&gt;
&lt;li&gt;Models, ViewModels, Views, Partial views, Controllers, ViewComponents&lt;/li&gt;
&lt;li&gt;Dependency injection, Major dependency injection lifetimes, Services&lt;/li&gt;
&lt;li&gt;SQL Server configuration, EFCore migrations, Relationship types&lt;/li&gt;
&lt;li&gt;Authentication, Authorization, Cookie-based Authentication&lt;/li&gt;
&lt;li&gt;Azure Deployment&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, In this section, we will talk about MVC architecture at a high level.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is MVC mean?&lt;/strong&gt;&lt;br&gt;
The Model-View-Controller (MVC) is an architectural design pattern that divides a software application/system into three main logical components,&lt;/p&gt;

&lt;p&gt;The model&lt;br&gt;
The view&lt;br&gt;
The controller&lt;br&gt;
Each of these components is made to control and manage specific development domains in an application.&lt;/p&gt;

&lt;p&gt;MVC is one of the most frequently used industry-standard web development frameworks to create scalable and extensible projects.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsfi41ca3i9a02bz8pbkp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsfi41ca3i9a02bz8pbkp.png" alt=" " width="444" height="281"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Model&lt;/strong&gt;&lt;br&gt;
In basic C# ASP .NET Core Web applications, it acts as a C# class which holds application data as a Data Blueprint. It also manages the Database operations and relations.&lt;/p&gt;

&lt;p&gt;Ex: Buyer, Seller, Admin User, Categories Classes in e-commerce Applications&lt;/p&gt;

&lt;p&gt;So Basically, The Model component corresponds to all the data-related logic that the user works with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;View&lt;/strong&gt;&lt;br&gt;
The view is a component that displays the user interface. In C#, It’s the CSHTML file (Razor Views). This handles the app's data presentation and user interaction&lt;/p&gt;

&lt;p&gt;In view, you can trigger/notify the events that get handled by the controllers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Controller&lt;/strong&gt;&lt;br&gt;
A controller controls the workflow that a user interacts with MVC application*.* A controller contains the flow control logic for an ASP.NET MVC application. A controller determines what response to send back to a user when a user makes a browser request.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>mvc</category>
    </item>
  </channel>
</rss>
